Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No provider found for OAuth2AuthorizationCodeAuthenticationToken when running Spring Native Reactive app using OAuth2 #12615

Closed
msosa opened this issue Feb 2, 2023 · 2 comments
Assignees
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: bug A general bug
Milestone

Comments

@msosa
Copy link
Contributor

msosa commented Feb 2, 2023

Describe the bug
Logging in using reactive OAuth2 built with native throws after redirect from OAuth2 server(Google in my case).

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:123) 

Do note that the non-reactive counterpart does work and is able to find the provider correctly.

To Reproduce
run gradlew bootBuildImage, run the docker image that is created, and attempt to login via OAuth2.

Expected behavior
Login with reactive Oauth2 without error

Sample

Here is a repo with a working example minus client id/secrets for the oauth2 client

@msosa msosa added status: waiting-for-triage An issue we've not yet triaged type: bug A general bug labels Feb 2, 2023
@marcusdacoregio marcusdacoregio self-assigned this Feb 2, 2023
@marcusdacoregio marcusdacoregio added in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 2, 2023
@marcusdacoregio marcusdacoregio added this to the 6.0.2 milestone Feb 3, 2023
@marcusdacoregio
Copy link
Contributor

Hi @msosa, thanks for the report.

The problem here is that there is no hint for JwtDecoder that is used here. In the meantime, while I'm working on the fix and the version is not released, you can workaround that by changing your application to include that hint:

@SpringBootApplication
@ImportRuntimeHints(MyHints::class)
class ReactiveOauth2Application

fun main(args: Array<String>) {
	runApplication<ReactiveOauth2Application>(*args)
}


class MyHints: RuntimeHintsRegistrar {

	override fun registerHints(hints: RuntimeHints, classLoader: ClassLoader?) {
		hints.reflection().registerType(TypeReference.of("org.springframework.security.oauth2.jwt.JwtDecoder"), MemberCategory.INVOKE_PUBLIC_CONSTRUCTORS)
	}

}

@msosa
Copy link
Contributor Author

msosa commented Feb 3, 2023

Awesome! I did try adding a few hints but not this one. Appreciate you looking into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: oauth2 An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants