Skip to content
ecdsa.com
Nimbus JOSE + JWT (Java)Java

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

How to fix it

  1. 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. 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

Related errors

Browse the full signature error database