Describe the bug - import the ‘spring-security/samples/boot/oauth2resourceserver-static’ into my IDE and run OAuth2ResourceServerApplication. - export TOKEN=eyJhbGciOiJS..... - curl -H "Authorization: Bearer $TOKEN" localhost:8080

then make a exception:

2020-09-23 11:29:24.288  INFO 21118 --- [    Test worker] c.dsp.soy.auth.SoyAuthApplicationTests   : Started SoyAuthApplicationTests in 2.886 seconds (JVM running for 3.892)

com.nimbusds.jose.Header.toJSONObject()Ljava/util/Map;
java.lang.NoSuchMethodError: com.nimbusds.jose.Header.toJSONObject()Ljava/util/Map;
    at org.springframework.security.oauth2.jwt.NimbusJwtDecoder.createJwt(NimbusJwtDecoder.java:154)
    at org.springframework.security.oauth2.jwt.NimbusJwtDecoder.decode(NimbusJwtDecoder.java:136)
    at org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationProvider.getJwt(JwtAuthenticationProvider.java:97)
    at org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationProvider.authenticate(JwtAuthenticationProvider.java:88)
    at org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:199)

I haven't changed any files. Why is this happening? I found that com.nimbusds.jose has a toJSONObject() method Can you help me solve this problem Spring Security Problems using spring-security examples(soauth2resourceserver-static)

Comment From: dousp

  • I found the cause of the problem,
  • nimbus-jose-jwt requires the latest version, such as 9.0.1.
  • But what I don’t know is: using version 8.19 will throw the exception shown in the picture above; but the toJSONObject() method is also found in version 8.19

Comment From: swarupdonepudi

  • I found the cause of the problem,
  • nimbus-jose-jwt requires the latest version, such as 9.0.1.
  • But what I don’t know is: using version 8.19 will throw the exception shown in the picture above; but the toJSONObject() method is also found in version 8.19

thanks a lot for posting your solution. helped me today.