Skip to content

Consider allowing a custom JwtBearerHandler implementation in AddJwtBearerΒ #62658

@paulomorgado

Description

@paulomorgado

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.

Sometimes there are simple requires that can be achieved by overriding HandleAuthenticateAsync on JwtBearerHandler.

But getting all functionality is not possible because AddJwtBearer cannot be replicated because it uses a JwtBearerConfigureOptionsthat isinternal`.

Tu use it, I've been replacing the JwtBearerHandler registration:

 services
     .AddAuthentication()
     .AddJwtBearer(authenticationScheme)
     ;

 // Replace JwtBearerHandler with MyTokenHandler
 services.RemoveAll<JwtBearerHandler>();
 services.AddTransient<JwtBearerHandler, MyTokenHandler>();

Because it's registered with services.AddTransient instead of services.TryAddTransient.

Describe the solution you'd like

 services
     .AddAuthentication()
     .AddJwtBearer<MyTokenHandler>(authenticationScheme)
     ;

Additional context

Or just use services.TryAddTransient to register JwtBearerHandler.

Metadata

Metadata

Assignees

Labels

Needs: Attention πŸ‘‹This issue needs the attention of a contributor, typically because the OP has provided an update.area-authIncludes: Authn, Authz, OAuth, OIDC, Bearer

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions