【问题标题】:Not getting additional claims from HttpContext.Current.GetOwinContext().Authentication没有从 HttpContext.Current.GetOwinContext().Authentication 获得额外的声明
【发布时间】:2017-10-23 13:09:03
【问题描述】:

我有一个使用 Owin 和 Identity Server 4 进行身份验证的 .net 表单客户端,但我没有收到额外的声明 HttpContext.Current.GetOwinContext().Authentication.User。我做错了什么?

我正在 IDS4 上的 accountController 中添加额外的声明,如下所示:

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)

【问题讨论】:

    标签: c# owin openid-connect identityserver4 claims


    【解决方案1】:

    您是否收到此声明属性中的声明:

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

    这是我将它与 Owin 和 cookie 身份验证一起使用的方式,它可以完美运行

    【讨论】:

    • 谢谢@Verthosa!我现在得到了所有这些:) 出于某种原因,我认为我必须从 HttpContext.Current.GetOwinContext().Authentication.User.Claims 获取它们
    • 请注意IPrincipal 可能是一个ClaimsPrincipal,它可以有多个ClaimsIdentity 来获取声明。如果 HttpContext.Current.UserClaimsPrincipal,您可以从所有附加的身份中获取 all claims
    猜你喜欢
    • 1970-01-01
    • 2018-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-25
    相关资源
    最近更新 更多