【问题标题】:How to request additional claims for access token in identity server 4 / auth code flow?如何在身份服务器 4/身份验证代码流中请求访问令牌的附加声明?
【发布时间】:2018-04-09 14:47:46
【问题描述】:

如何在身份服务器 4/身份验证代码流中为访问令牌 jwt 请求额外声明?在我的身份验证代码流登录期间,我的自定义配置文件服务始终显示 RequestedClaimTypes 为 0,因此生成的访问令牌 jwt 具有我的主题声明,但没有名字、姓氏或电子邮件声明。

这是我从客户那里请求的范围: "TestApi openid 个人资料电子邮件"

这是我在身份服务器上的客户端定义:

 new Client {                    
                ClientId = "authorizationCodeClient2",
                ClientName = "Authorization Code Test",
                ClientSecrets = {
                                        new Secret("secret".Sha256())
                                },
                Enabled = true,
                AllowedGrantTypes = GrantTypes.Code,
                RequireConsent = true,
                AllowRememberConsent = false,
                RedirectUris =
                new List<string> {
                 "http://localhost:5436/account/oAuth2"
                },                    
                AllowedScopes = { "TestApi", "openid", "profile", "email" },
                AccessTokenType = AccessTokenType.Jwt
            }

https://github.com/bayardw/IdentityServer4.Authorization.Code 用于测试客户端。

【问题讨论】:

    标签: identityserver4


    【解决方案1】:

    我发现身份服务器可以让您有选择地使用用户配置文件声明标记 id 令牌(而不必调用 userinfo 端点)。您基本上为该特定客户端设置了一个布尔属性:

    AlwaysIncludeUserClaimsInIdToken = true;

    注意,您需要在您的身份验证请求中请求以下范围:(openid 个人资料电子邮件)

    【讨论】:

    • 请注意,如果您有很多声明,当它具有一定大小时,它可能会遇到与 IdentityServer 交互的问题。我遇到了这个,我不记得我遇到的确切限制或场景。
    猜你喜欢
    • 2012-06-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-27
    • 2020-01-15
    相关资源
    最近更新 更多