【问题标题】:How to request claim types in IdentityServer4?如何在 IdentityServer4 中请求声明类型?
【发布时间】:2017-08-08 09:39:00
【问题描述】:

我正在关注这个post 来实现 IdentityServer4。我有问题,在过程 GetProfileDataAsync IEnumerable context.RequestedClaimTypes 中的 ProfileService 为空。我应该在 Postman 中更改我的请求以请求某些索赔类型吗?我该怎么做才能使 context.RequestedClaimTypes 包含声明类型?

我的 Postman 请求如下所示:

Post http://localhost:57577/connect/token
Authorization: Basic Z2xvYmFsX2F...
Body (x-www-form-urlencoded):
username:user@gmail.com
password:pass
grant_type:password
scope:my_api

【问题讨论】:

    标签: asp.net-core identityserver4


    【解决方案1】:

    就像您关注的帖子一样,您必须在 scope 中请求它。您可以将profile email 添加到其中,然后您应该得到这些声明。确保将它们添加到 AllowedScopes 下的客户端配置 (config.cs) 中。

    【讨论】:

    • 这几乎完全解决了我的问题。姓名和电子邮件在 context.RequestedClaimTypes 中可用,但主题仍然不可用。我将 JwtClaimTypes.Subject 添加到 UserClaims。在 Scopes 中,我添加了“my_api”、“openid”、“profile”、“email”。在客户端中,我添加了 AllowedScopes:“my_api”、“openid”、“profile”、“email”、“sub”。在 Postman 中,范围包含“my_api openid profile email”。
    • JwtClaimTypes.Subject ("sub") 声明将默认包含在 API 中的 User.Claims 中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-16
    • 2023-03-15
    • 1970-01-01
    • 2021-10-06
    相关资源
    最近更新 更多