How to use InboundClaimTypeMap for claim mapping?

好久不见. 提交于 2020-01-24 12:12:47

问题


I have similar problem as here : https://github.com/IdentityServer/IdentityServer3.Samples/issues/9

But solution is not helpful for me.

So lets explain in more details with pictures and code:

I have this on client:

No need to map because NameClaimType(RoleClaimType) and Claim in list of claims are same

JwtSecurityTokenHandler.InboundClaimTypeMap.Clear();

On Api project I have:

In this case (if I understand correctly), I have to to map, because NameClaimType & RoleClaimType are not same with claim values.

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

But still not working. What am I doing wrong?


回答1:


InboundClaimTypeMap is used to transform the incoming claims. It doesn't set the NameClaimType and RoleClaimType properties.

Your authentication middleware should have the option to set name and role claim types. For ex:-

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


来源:https://stackoverflow.com/questions/35622624/how-to-use-inboundclaimtypemap-for-claim-mapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!