Error message
Signed JWT rejected: Another algorithm expected, or no matching key(s) found
Also printed as
- com.nimbusds.jose.proc.BadJOSEException: Signed JWT rejected: Another algorithm expected, or no matching key(s) found
- org.springframework.security.oauth2.jwt.BadJwtException: An error occurred while attempting to decode the Jwt: Signed JWT rejected: Another algorithm expected, or no matching key(s) found
Nimbus JOSE + JWT (Java) — BadJOSEException from DefaultJWTProcessor; also surfaced by Spring Security's NimbusJwtDecoder
What it means
Nimbus's key selector returned no candidate key for this token: either the token's `alg` is not one of the algorithms the selector accepts, or no key in the JWK set matches the token's `kid` and key type. Nimbus deliberately does not say which of the two it was. Behind Spring Security this is very often the RS256 default of `NimbusJwtDecoder` meeting an issuer that signs with ES256.
Why it happens
The verifier expects RS256
commonSpring Security's `NimbusJwtDecoder` uses RS256 unless you configure algorithms (or it discovers them from the issuer's JWKS in newer versions). Keycloak, Auth0, Azure AD B2C and others can sign with ES256/PS256.
The token's kid is not in the JWK set
commonA rotated key not yet published, a cached JWK set, or a JWK set URL belonging to another issuer or environment.
Key metadata excludes the key
occasionalJWKs with `use: "enc"`, a different `alg`, or another key type (an RSA key set for an ES256 token) are filtered out by the matcher.
How to fix it
- 1.
Tell the decoder which algorithm the issuer uses
`jwsAlgorithm(...)` (or `jwsAlgorithms(...)`) on the builder replaces the RS256 default. Keep the list to the issuer's real algorithms.
java @Bean JwtDecoder jwtDecoder() { return NimbusJwtDecoder.withIssuerLocation("https://issuer.example.com/realms/main") .jwsAlgorithm(SignatureAlgorithm.ES256) // the issuer's algorithm; RS256 is only the default .build(); } - 2.
Or configure it in application.yml
Spring Boot exposes the same setting as `jws-algorithms`.
yaml spring: security: oauth2: resourceserver: jwt: issuer-uri: https://issuer.example.com/realms/main jws-algorithms: ES256