Search code examples
c#owinopenid-connectidentityserver4claims

Not getting additional claims from HttpContext.Current.GetOwinContext().Authentication


I have a .net form client that uses Owin and Identity Server 4 for authentications and I don't get the additional claims back from HttpContext.Current.GetOwinContext().Authentication.User. What am I doing wrong?

I am adding the additional claims in my accountController on IDS4 like this:

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

On my Client:

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)

Solution

  • Do you recieve the claims in the Claims property of this:

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

    This is they way i use it with Owin and cookie authentication and it works flawlessly