【问题标题】:How to use InboundClaimTypeMap for claim mapping?如何使用 InboundClaimTypeMap 进行声明映射?
【发布时间】:2016-06-07 22:49:50
【问题描述】:

我有类似的问题:https://github.com/IdentityServer/IdentityServer3.Samples/issues/9

但解决方案对我没有帮助。

那么让我们用图片和代码更详细地解释一下:

我在客户端上有这个:

无需映射,因为 NameClaimType(RoleClaimType) 和声明列表中的声明相同

JwtSecurityTokenHandler.InboundClaimTypeMap.Clear();

在 Api 项目上我有:

在这种情况下(如果我理解正确的话),我必须映射,因为 NameClaimType 和 RoleClaimType 与声明值不同。

    JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>
    {
        {"role", System.Security.Claims.ClaimTypes.Role},
        {"name",System.Security.Claims.ClaimTypes.Name }
    };

但仍然无法正常工作。我做错了什么?

【问题讨论】:

    标签: c# asp.net-web-api thinktecture-ident-server


    【解决方案1】:

    InboundClaimTypeMap 用于转换传入的声明。它没有设置NameClaimTypeRoleClaimType 属性。

    您的身份验证中间件应具有设置名称和角色声明类型的选项。例如:-

    app.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
                    {
                        ...,
                        NameClaimType = System.Security.Claims.ClaimTypes.Name,
                        RoleClaimType = System.Security.Claims.ClaimTypes.Role 
                    });
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-07
    • 2020-07-30
    • 1970-01-01
    相关资源
    最近更新 更多