-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Is there an existing issue for this?
- I have searched the existing issues
Is your feature request related to a problem? Please describe the problem.
The JwtBearerConfigureOptions class reads values for both the ValidIssuer and the ValidAudience from the configuration and even saves them to the ValidIssuers and ValidAudiences collections in the TokenValidationParameters, but completely ignores the corresponding ValidIssuer and ValidAudience properties of the same TokenValidationParameters.
The simplified representation of what is happening right now:
// Load ValidIssuers from authentication configuration.
var issuers = configSection
.GetSection(nameof(TokenValidationParameters.ValidIssuers))
.GetChildren()
.Select(iss => iss.Value)
.ToList();
// Also load a ValidIssuer from the authentication configuration, then add it
// to the ValidIssuers collection.
var issuer = configSection[nameof(TokenValidationParameters.ValidIssuer)];
if (issuer is not null)
{
issuers.Add(issuer);
}
// Load ValidAudiences from authentication configuration.
var audiences = configSection
.GetSection(nameof(TokenValidationParameters.ValidAudiences))
.GetChildren()
.Select(aud => aud.Value)
.ToList();
// Also load a ValidAudience from the authentication configuration, then add it
// to the ValidAudiences collection.
var audience = configSection[nameof(TokenValidationParameters.ValidAudience)];.
if (audience is not null)
{
audiences.Add(audience);
}
// Only populate the ValidIssuers and the ValidAudiences properties, completely
// ignoring the ValidIssuer and the ValidAudience properties.
options.TokenValidationParameters = new()
{
ValidIssuers = issuers,
ValidAudiences = audiences
};
Note
Please note that this is a very abbreviated code example and that it differs significantly from the actual JwtBearerConfigureOptions.Configure method implementation.
Describe the solution you'd like
I would like that if configuration explicitly specifies a value for the ValidIssuer and ValidAudience, that value will end up in the TokenValidationParameters.
Basically, I would like the JwtBearerConfigureOptions.Configure method to also populate the ValidIssuer and the ValidAudience properties too:
// Load ValidIssuers from authentication configuration.
var issuers = configSection
.GetSection(nameof(TokenValidationParameters.ValidIssuers))
.GetChildren()
.Select(iss => iss.Value)
.ToList();
// Also load a ValidIssuer from the authentication configuration, then add it
// to the ValidIssuers collection.
var issuer = configSection[nameof(TokenValidationParameters.ValidIssuer)];
if (issuer is not null)
{
issuers.Add(issuer);
}
// Load ValidAudiences from authentication configuration.
var audiences = configSection
.GetSection(nameof(TokenValidationParameters.ValidAudiences))
.GetChildren()
.Select(aud => aud.Value)
.ToList();
// Also load a ValidAudience from the authentication configuration, then add it
// to the ValidAudiences collection.
var audience = configSection[nameof(TokenValidationParameters.ValidAudience)];.
if (audience is not null)
{
audiences.Add(audience);
}
// Only populate the ValidIssuers and the ValidAudiences properties, completely
// ignoring the ValidIssuer and the ValidAudience properties.
options.TokenValidationParameters = new()
{
+ ValidIssuer = issuer,
ValidIssuers = issuers,
+ ValidAudience = audience,
ValidAudiences = audiences
};