Home >Backend Development >C++ >How to Support Multiple JWT Token Issuers in ASP.NET Core?
This guide demonstrates how to configure ASP.NET Core to authenticate using multiple JWT token issuers by defining separate authentication schemes.
Create a custom JWT bearer scheme:
<code class="language-csharp">services.AddAuthentication("Custom") .AddJwtBearer("Custom", options => { // Custom issuer configuration... });</code>
To enable authentication using both Firebase and your custom scheme, modify the default authorization policy:
<code class="language-csharp">services.AddAuthorization(options => { options.DefaultPolicy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .AddAuthenticationSchemes("Firebase", "Custom") .Build(); });</code>
Specify JWT bearer options for each authentication scheme:
<code class="language-csharp">services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer("Firebase", options => { options.Authority = "https://securetoken.google.com/my-firebase-project"; options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidIssuer = "my-firebase-project", ValidateAudience = true, ValidAudience = "my-firebase-project", ValidateLifetime = true }; });</code>
IDX10501
errors appropriately when using multiple schemes (e.g., by ignoring them).The above is the detailed content of How to Support Multiple JWT Token Issuers in ASP.NET Core?. For more information, please follow other related articles on the PHP Chinese website!