-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple jwt authentication schemes can't validate signature key #26002
Comments
In debug console I have this error :
|
@HaoK does multiple auth of the same type fail fast, or would removing the default scheme work (and adding a default challenge to have challenge work?) |
Removing the default scheme and replacing it by a challenge still produces the error, if that's what you mean. JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();
services.AddAuthentication()
.AddJwtBearer("Dev", ConfigureJwtBearer.CreateJwtBearer(env, settings, "authority 1"))
.AddJwtBearer("Staging", ConfigureJwtBearer.CreateJwtBearer(env, settings, "authority 2"))
.AddJwtBearer("Prod",ConfigureJwtBearer.CreateJwtBearer(env, settings, "authority 3"));
services.AddAuthorization(options =>
{
var defaultAuthorizationPolicyBuilder = new AuthorizationPolicyBuilder(
"Dev", "Staging", "Prod");
defaultAuthorizationPolicyBuilder =
defaultAuthorizationPolicyBuilder.RequireAuthenticatedUser();
options.DefaultPolicy = defaultAuthorizationPolicyBuilder.Build();
}); |
Multiple schemes of the same name will fail fast, that's the only thing we guard against. In this case, they are called Dev/Staging/Prod so they are all logically different. You are allowed to have 3 JwtBearers configured. |
The problem was caused by an internal package which had the wrong version of Microsoft.AspNetCore.Authentication.JwtBearer in its dependencies. |
Describe the bug
When using multiple jwt authentication schemes, the last scheme always falls in 401 with Bearer error="invalid_token", error_description="The signature key was not found" and Bearer error="invalid_token", error_description="The signature is invalid" x2 in 3 separate WWW-Authenticate headers.
To Reproduce
The first two schemes work but the Prod scheme doesn't. If I put the Prod scheme before the Staging scheme, Prod works and Staging doesn't.
Exceptions (if any)
Further technical details
The text was updated successfully, but these errors were encountered: