I am using IdentityServer4 IDP with a blazor client. In a razor component I have:
[CascadingParameter]
public Task<AuthenticationState> AuthenticationStateTask { get; set; }
async Task GetClaims()
{
var claims = (await AuthenticationStateTask).User.Claims;
}
This gives me a total of 9 claims including sub
, name
, preferred_name
, amr
, email
, email_verified
etc. I want to also get the phone number here but it is not present even though I add phone scope in the IDP config as following
public static IEnumerable<IdentityResource> Ids =>
new IdentityResource[]
{
new IdentityResources.OpenId(), // sub
new IdentityResources.Profile(), // givenName, familyName ..
new IdentityResources.Email(),
new IdentityResources.Phone()
};
and in Client object;
AllowedScopes = {
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Email,
IdentityServerConstants.StandardScopes.Phone,
"exampleapi" },
Doesn't this mean that the phone number should be in the identity token? What should I do to get the phone number?
Also, what is the best way to send a phoneNumberUpdate
request?
Client Oidc service registration also needs to be configured to ask for phone scope
builder.Services.AddOidcAuthentication(options =>
{
//...
options.ProviderOptions.DefaultScopes.Add("phone");
//...
});