Consider allowing a custom JwtBearerHandler implementation in AddJwtBearer
- 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.
Sometimes there are simple requires that can be achieved by overriding `HandleAuthenticateAsync` on `JwtBearerHandler`.
But getting all functionality is not possible because [`AddJwtBearer`](https://learn.microsoft.com/en-us/dotnet/api/microsoft.extensions.dependencyinjection.jwtbearerextensions.addjwtbearer) cannot be replicated because it uses a [`JwtBearerConfigureOptions`](https://source.dot.net/Microsoft.AspNetCore.Authentication.JwtBearer/JwtBearerConfigureOptions.cs.html#d166882dc93bfcaa)` that is `internal`.
Tu use it, I've been replacing the `JwtBearerHandler` registration:
```csharp
services
.AddAuthentication()
.AddJwtBearer(authenticationScheme)
;
// Replace JwtBearerHandler with MyTokenHandler
services.RemoveAll();
services.AddTransient();
```
Because it's registered with `services.AddTransient` instead of `services.TryAddTransient`.
### Describe the solution you'd like
```csharp
services
.AddAuthentication()
.AddJwtBearer(authenticationScheme)
;
```
### Additional context
Or just use `services.TryAddTransient` to register `JwtBearerHandler`.
Contributor guide
Assessment
This issue has not been assessed yet.