Error when using Spring Security 5 and Auth0

Viewed 200

I am configuring my Spring Boot application using auth0. For that I am using the following tutorial: https://auth0.com/docs/quickstart/backend/java-spring-security5

But I am getting the following error:"

class com.nimbusds.jose.Algorithm cannot be cast to class com.nimbusds.jose.JWSAlgorithm (com.nimbusds.jose.Algorithm and com.nimbusds.jose.JWSAlgorithm are in unnamed module of loader 'app')

I am using Spring Boot 2.5.0-M2, and Kotlin (just in case it matters)

1 Answers

It is a bug in 5.5.0 pre releases of spring security which is used by spring boot 2.5.0.

There is a PR to fix this that hopefully will be released soon.

Until then you can create the JwTDecoder as a workaround:

@Bean 
JwtDecoder jwtDecoder() {
    String issuerUri = ...;
    String jwkSetUri = ...;
    OAuth2TokenValidator<Jwt> validator = JwtValidators.createDefaultWithIssuer(issuerUri);
    NimbusJwtDecoder jwtDecoder = NimbusJwtDecoder.withJwtSetUri(jwkSetUri).build();
    jwtDecoder.setJwtValidator(validator);
    return jwtDecoder;
}
Related