IdentityServer4 Client prop声明无法在MongoDB中设置

问题描述 投票:1回答:1

我想用它来向MongoDB Collection Client插入新客户端:

                new Client
            {
                ClientId = "clientB",
                // 没有交互性用户,使用 clientid/secret 实现认证。
                AllowedGrantTypes = GrantTypes.ClientCredentials,
                // 用于认证的密码
                ClientSecrets =
                {
                    new Secret("secretB".Sha256())
                },
                // 客户端有权访问的范围(Scopes)
                AllowedScopes = { "api1" },
                Claims=new List<Claim>(){
                     new Claim( JwtClaimTypes.Role,"superadmin")
                }
            }

但是我明白了:

clientB MongoDB raw data

如您所见,无法设置属性Claims,为什么?谢谢!

asp.net identityserver4 core
1个回答
0
投票

Identity令牌从IdentityServer返回,但不包括声明。IdentityServer在身份令牌中不包括身份声明(子项除外),除非您明确要求(不推荐)即像这样...

new Client {
    ClientId = "myclient",
    AlwaysIncludeUserClaimsInIdToken = true,    //not a good idea
...

这里有一些关于此主题的额外信息。默认情况下,IdentityServer在身份令牌中不包含身份声明。通过将客户端配置上的AlwaysIncludeUserClaimsInIdToken设置设置为true,可以允许它。但是不建议这样做。初始身份令牌是通过表单发布或URI通过前通道通信从授权端点返回的。如果通过URI返回并且令牌太大,则可能会遇到URI长度限制,该限制仍取决于浏览器。大多数现代浏览器的长URI都没有问题,但是Internet Explorer等较旧的浏览器可能会出现问题。这可能与您无关,也可能与您无关。看起来我的项目与您的项目相似。祝你好运。

© www.soinside.com 2019 - 2024. All rights reserved.