2017-05-23 30 views
0

我有一個.net表單客戶端,它使用Owin和Identity Server 4進行身份驗證,我沒有從 得到額外的聲明HttpContext.Current.GetOwinContext ().Authentication.User。我究竟做錯了什麼?沒有從HttpContext.Current.GetOwinContext()獲得附加聲明身份驗證

我加入我的AccountController額外的債權IDS4這樣的:

await HttpContext.Authentication.SignInAsync(user.SubjectId, user.Username, props, additionalClaims.ToArray()); 

在我的客戶:

if (!Request.IsAuthenticated) 
      {    

       HttpContext.Current.GetOwinContext().Authentication.Challenge(
        new AuthenticationProperties 
        { 
         RedirectUri = "/Default1.aspx", 

        },     
        OpenIdConnectAuthenticationDefaults.AuthenticationType); 

      } 
      else 
      {   
       foreach (var claim in HttpContext.Current.GetOwinContext().Authentication.User.Claims) 

回答

1

你收到在此索賠財產的權利:

var claimsIdentity = HttpContext.Current.User.Identity as ClaimsIdentity; 

這是他們的方式,我用它與歐文和cookie認證,它的作品完美無缺

+0

謝謝@Verthosa!我現在得到他們所有:)由於某種原因,我認爲我必須從HttpContext.Current.GetOwinContext()獲取它們。Authentication.User.Claims – cvetyab

+1

請注意,'IPrincipal'可能是'ClaimsPrincipal',可以有多個'ClaimsIdentity'從中提取索賠。如果* HttpContext.Current.User *是'ClaimsPrincipal',您可以獲取[所有聲明](https://msdn.microsoft.com/en-us/library/system.security.claims.claimsprincipal.claims.aspx)來自所有附加身份。 – ckerth