【问题标题】:How to add phone number claim on IdentityServer4如何在 IdentityServer4 上添加电话号码声明
【发布时间】:2021-04-10 08:34:44
【问题描述】:

我正在将 IdentityServer4 IDP 与 blazor 客户端一起使用。在剃须刀组件中,我有:

[CascadingParameter]
public Task<AuthenticationState> AuthenticationStateTask { get; set; }

async Task GetClaims()
{
    var claims = (await AuthenticationStateTask).User.Claims;
}

这给了我总共 9 个声明,包括 subnamepreferred_nameamremailemail_verified 等。我也想在这里获取电话号码,但不是即使我在 IDP 配置中添加电话范围如下

public static IEnumerable<IdentityResource> Ids =>
    new IdentityResource[]
    {
        new IdentityResources.OpenId(), // sub
        new IdentityResources.Profile(), // givenName, familyName ..
        new IdentityResources.Email(),
        new IdentityResources.Phone()
    };

在客户端对象中;

AllowedScopes = {
    IdentityServerConstants.StandardScopes.OpenId,
    IdentityServerConstants.StandardScopes.Profile,
    IdentityServerConstants.StandardScopes.Email,
    IdentityServerConstants.StandardScopes.Phone,
    "exampleapi" },

这不是说电话号码应该在身份令牌中吗?我应该怎么做才能得到电话号码?

另外,发送phoneNumberUpdate 请求的最佳方式是什么?

【问题讨论】:

    标签: c# asp.net blazor identityserver4


    【解决方案1】:

    spec 说:

    个人资料、电子邮件、地址和电话范围请求的声明 值从 UserInfo 端点返回,如中所述 第 5.3.2 节,当使用导致 正在发行访问令牌。但是,当没有颁发访问令牌时 (response_type 值 id_token 就是这种情况), 生成的声明在 ID 令牌中返回。

    UserInfo Endpoint

    【讨论】:

    • 不幸的是,IdentityServer4 的文档几乎没有提供任何信息。而且 OpenId 规范没有说明任何特定于 aspnet 的内容。
    • 很高兴您找到了解决方案。
    【解决方案2】:

    客户端Oidc服务注册也需要配置要求电话范围

    builder.Services.AddOidcAuthentication(options =>
    {
        //...
        options.ProviderOptions.DefaultScopes.Add("phone");
        //...
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-07-26
      • 1970-01-01
      • 2020-08-20
      • 1970-01-01
      • 1970-01-01
      • 2017-09-14
      • 2015-12-04
      相关资源
      最近更新 更多