如何在IdentityServer4中请求身份令牌(id_token)

3

我刚接触Identity Server,对身份和访问令牌这个话题感到困惑。我知道访问令牌是用来保护资源(例如Web API)的,而身份令牌则用于身份验证。然而,每当我调用/connect/token时,我总是收到一个“access_token”。在请求中,我要求客户端具有各种范围和声明。

new Client
            {             
                ClientId = "Tetris",
                ClientName = "Tetris Web Api",
                AccessTokenLifetime = 60*60*24,
                AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
                RequireClientSecret = false,
                AllowedScopes = {"openid", "TetrisApi", "TetrisIdentity"}
            }



public static IEnumerable<ApiResource> GetApiResources()
        {
            return new[]
            {
                new ApiResource("TetrisApi", "Tetris Web API", new[] { JwtClaimTypes.Name, JwtClaimTypes.Role, "module" })
            };
        }

        public static IEnumerable<IdentityResource> GetIdentityResources()
        {
            return new List<IdentityResource>
            {
                new IdentityResources.OpenId(),
                new IdentityResources.Profile(),
                new IdentityResource
                {
                    Name = "TetrisIdentity",
                    UserClaims =
                        new[]
                        {
                            JwtClaimTypes.Name,
                            JwtClaimTypes.Role,
                            JwtClaimTypes.GivenName,
                            JwtClaimTypes.FamilyName,
                            JwtClaimTypes.Email,
                            "module",
                            "module.permissions"
                        }
                }
            };
        }

以下是Postman的副本: enter image description here 有什么想法吗?我没有在快速入门中看到使用身份令牌的示例。
谢谢!
2个回答

3

密码授予类型不支持身份标记,请参阅RFC6749。

在此处,您最好使用访问令牌通过userinfo端点获取用户的声明。

建议使用类似暗示或混合的交互式流进行最终用户身份验证。


谢谢。我正按照你建议的方式进行操作 - 调用userinfo端点。在Postman中,我可以使用哪种授权类型来获取身份令牌? - Greg

2
@leastprivilege的回答是正确的,但是除了调用userinfo端点之外,您还可以选择在ApiResource定义中包含您所需的UserClaims
目前,您请求的是new[] { JwtClaimTypes.Name, JwtClaimTypes.Role, "module" },但如果您将其更改为包括所有您(当前)定义为IdentityResources的声明,则这些声明也将在访问令牌中可用。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接