2016-11-17 13 views
3

私はAzure Active DirectoryでAdalを使用しており、カスタムOwinMiddleware経由で余分なクレームを追加する必要があります。 このプリンシパルにクレームを追加すると、現在のリクエストでクレームにアクセスすることができます。しかし、ページが更新された後、その申し立ては消えてしまいます。ClaimsPrincipalのクレームを更新する

私はOwinがクレームのシリアル化を処理し、それをクッキー自体に入れると考えましたが、これはそうではないようです。次のように

私は、特許請求の範囲を追加します。

var claimsIdentity = (ClaimsIdentity) ClaimsPrincipal.Current.Identity; 
     if (!claimsIdentity.IsAuthenticated) return; 

     var identity = new ClaimsIdentity(claimsIdentity); 

     var currentTenantClaim = GetTenantClaim(); 

     if (currentTenantClaim != null) 
      claimsIdentity.RemoveClaim(currentTenantClaim); 

     claimsIdentity.AddClaim(new Claim(ClaimTypes.CurrentTenantId, id)); 

     context.Authentication.AuthenticationResponseGrant = new AuthenticationResponseGrant 
      (new ClaimsPrincipal(identity), new AuthenticationProperties {IsPersistent = true}); 

クッキーに新しいクレームを永続化する方法上の任意のアイデア?

答えて

3

誤ったIDにクレームを追加しました。それらはclaimIdentityではなくidentity変数に追加する必要がありました。

の作業コード:

 var claimsIdentity = (ClaimsIdentity) context.Authentication.User.Identity; 
     if (!claimsIdentity.IsAuthenticated) return; 

     var identity = new ClaimsIdentity(claimsIdentity); 

     var currentTenantClaim = GetTenantClaim(identity); 

     if (currentTenantClaim != null) 
      identity.RemoveClaim(currentTenantClaim); 

     identity.AddClaim(new Claim(ClaimTypes.CurrentTenantId, id)); 

     context.Authentication.AuthenticationResponseGrant = new AuthenticationResponseGrant 
      (new ClaimsPrincipal(identity), new AuthenticationProperties {IsPersistent = true}); 
関連する問題