【问题标题】:How can client get resource claims about the user in IdentityServer4客户端如何在 IdentityServer4 中获取有关用户的资源声明
【发布时间】:2017-09-06 21:30:20
【问题描述】:

我的客户从IdentityServer4 获得令牌并将其交给我的API 以获得服务, 直到我想要获得用户声明(STS 自动将用户声明放在用户声明上)之前,一切都是真的,当我调用 User.Identity.Name 时,它返回 null。 根据This Link我应该在API启动中定义Scope,所以我定义:

  app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
        {
            Authority = "http://localhost:33934",
            RequireHttpsMetadata = false,
            ApiName = "api1",
            AllowedScopes = { "profile", "email", "api1" },
        });

一切顺利,我的用户可以从 IdentityServer 获取 Token,当我将它传递给 API 时,Authorization 将成功完成,但 User.Identity.Name 返回 null! 有什么问题?

【问题讨论】:

    标签: .net-core identityserver4


    【解决方案1】:

    您可以使用

    打印出索赔清单
    <dl>
        @foreach (var claim in User.Claims)
        {
            <dt>@claim.Type</dt>
            <dd>@claim.Value</dd>
        }
    </dl>
    

    在客户端应用程序上试试这个,你就会知道你是否在名义上获得价值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-28
      • 2020-03-27
      • 1970-01-01
      • 2020-05-26
      • 1970-01-01
      • 1970-01-01
      • 2012-11-23
      相关资源
      最近更新 更多