Hi jc199,
RoleClaimType
might not be automatically looked up because they may not be part of the predefined options that are supported for direct binding by the built-in configuration system.
You can manually bind custom options from appsettings.json
to the relevant options classes in your Program.cs
file:
builder.Services.AddAuthentication("Bearer")
.AddJwtBearer(options =>
{
var jwtSection = builder.Configuration.GetSection("Authentication:JwtBearer");
options.TokenValidationParameters.ValidIssuer = jwtSection["ValidIssuer"];
options.TokenValidationParameters.ValidAudiences = jwtSection.GetSection("ValidAudiences").Get<string[]>();
options.TokenValidationParameters.RoleClaimType = jwtSection["RoleClaimType"];
});
The json string should be like below:
{
"Authentication": {
"Bearer": {
"ValidAudiences": [
"https://localhost:7259",
"http://localhost:5259"
],
"ValidIssuer": "dotnet-user-jwts",
"RoleClaimType": "role"
}
}
}
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best regards,
Rena