dotnet / dotnet/aspnetcore

Make a way to configure more options in TokenValidationParameters using simplified authentication configuration

Open
#55,389 0 comments 0 reactions 0 assignees View on GitHub
area-auth enhancement
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

I'm working on a project where I'm using JWT Bearer tokens with simplified auth configuration like this:

```csharp
builder.Services.AddAuthentication().AddJwtBearer();
```

My `appsettings.json` looks like this:

```json
{
"Authentication": {
"Schemes": {
"Bearer": {
"Authority": "...",
"MetadataAddress": "...",
"ValidIssuer": "...",
"ValidAudiences": [ "account" ]
}
}
}
}
```

My application uses an OIDC server that has a different `NameClaimType` than ASP.NET Security's default. It would be great to be able to specify that in the same configuration (along with `RoleClaimType` and maybe other options left behind). Something like this:

```json
{
"Authentication": {
"Schemes": {
"Bearer": {
"Authority": "...",
"MetadataAddress": "...",
"ValidIssuer": "...",
"ValidAudiences": [ "account" ],
"TokenValidationParameters": {
"NameClaimType": "name"
}
}
}
}
}
```

### Describe the solution you'd like

It would be straightforward to add a few more options in [JwtBearerConfigureOptions.cs](https://github.com/dotnet/aspnetcore/blob/c157c5c1962a66c4fe0212ed767f167bb9cdfb79/src/Security/Authentication/JwtBearer/src/JwtBearerConfigureOptions.cs#L64) to configure `TokenValidationParameters` further from configuration.

I could make a PR myself. Let me know what you think.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.