No provider found for class OAuth2AuthorizationCodeAuthenticationToken when using oauth2login flow in spring security reactive #16453
Labels
for: stackoverflow
A question that's better suited to stackoverflow.com
Describe the bug
An error occurs when the application integrated Spring Gateway and Spring Security OAuth2 Client goes through the OAuth login process.
java.lang.IllegalStateException: No provider found for class org.springframework.security.oauth2.client.authentication.OAuth2AuthorizationCodeAuthenticationToken at org.springframework.security.web.server.authentication.AuthenticationWebFilter.lambda$authenticate$6(AuthenticationWebFilter.java:124) ~[spring-security-web-6.2.8.jar:6.2.8] Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: Error has been observed at the following site(s): *__checkpoint ⇢ OAuth2LoginAuthenticationWebFilter [DefaultWebFilterChain] *__checkpoint ⇢ OAuth2AuthorizationRequestRedirectWebFilter [DefaultWebFilterChain] *__checkpoint ⇢ ReactorContextWebFilter [DefaultWebFilterChain] *__checkpoint ⇢ HttpHeaderWriterWebFilter [DefaultWebFilterChain] *__checkpoint ⇢ ServerWebExchangeReactorContextWebFilter [DefaultWebFilterChain] *__checkpoint ⇢ org.springframework.security.web.server.WebFilterChainProxy [DefaultWebFilterChain] *__checkpoint ⇢ HTTP GET "/login/oauth2/code/capyId?code=LgletqbOVmz4Ae8ZBiseGO8rLQzxbfB__e7qloE7zc-TvH2WaFRqrOdqt8--p4E6JhglkkVjkfXFrOlrEuP-KYqFlohaJMOFijf-hEFRuDNUY3ne5NFIiEk0mEXJydVO&state=RZi5-LwSqzw6Yi_Um0c0zZj9HEHQq0Rjwhr6wc9XNZk%3D" [ExceptionHandlingWebHandler] Original Stack Trace: at org.springframework.security.web.server.authentication.AuthenticationWebFilter.lambda$authenticate$6(AuthenticationWebFilter.java:124) ~[spring-security-web-6.2.8.jar:6.2.8] at reactor.core.publisher.MonoDefer.subscribe(MonoDefer.java:45) ~[reactor-core-3.6.12.jar:3.6.12] at reactor.core.publisher.Mono.subscribe(Mono.java:4576) ~[reactor-core-3.6.12.jar:3.6.12]
To Reproduce
There are two applications in my project.
The first app is authorization-server, integrated spring-security-oauth2-authorization-server.
(authorization server has enabled OAuth2 and OIDC.)
The second is BFF(Backends For Frontends) app , integrated spring-cloud-gateway and spring-boot-starter-oauth2-client.
(this app has enabled oauth2login)
The OAuth2 login process can succeed only when the second application’s scope is configured as openid. If the scope is set to profile or myscope, the error will occur.
The error occurred in this URL request.
/login/oauth2/code/capyId?code=LgletqbOVmz4Ae8ZBiseGO8rLQzxbfB__e7qloE7zc-TvH2WaFRqrOdqt8--p4E6JhglkkVjkfXFrOlrEuP-KYqFlohaJMOFijf-hEFRuDNUY3ne5NFIiEk0mEXJydVO&state=RZi5-LwSqzw6Yi_Um0c0zZj9HEHQq0Rjwhr6wc9XNZk%3D
Expected behavior
I hope to successfully complete the OAuth2 login process without configuring the openid scope.
Sample
The authorization-server code:
The BFF app code:
The error occurred in this application.yaml
oauth2login succeed in this application.yaml
The text was updated successfully, but these errors were encountered: