Skip to content

Consider removing GatewayReactiveOAuth2AutoConfiguration #3493

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

Closed
sjohnr opened this issue Aug 12, 2024 · 5 comments · Fixed by #3528
Closed

Consider removing GatewayReactiveOAuth2AutoConfiguration #3493

sjohnr opened this issue Aug 12, 2024 · 5 comments · Fixed by #3528
Labels
Milestone

Comments

@sjohnr
Copy link
Contributor

sjohnr commented Aug 12, 2024

Expected Behavior

In Spring Security 6.3, we simplified configuration by introducing a new BeanDefinitionRegistryPostProcessor to register a ReactiveOAuth2AuthorizedClientManager bean if one is not already present.

Note that we aren't using @Conditional... annotations to register this bean since we don't depend on Spring Boot, and without @AutoConfigureAfter ordering would be an issue.

When both Spring Security and Spring Cloud Gateway are on the classpath with the TokenRelay filter in use, the reactive gateway's GatewayReactiveOAuth2AutoConfiguration registers a ReactiveOAuth2AuthorizedClientManager which prevents the one provided by Spring Security from being registered. Given the new feature in 6.3, I think we can remove the auto-configuration in reactive gateway and allow Spring Security to provide the bean during post-processing.

Additional context

I noticed this when working on a sample to enable the new Token Exchange feature in an OAuth2 Client that is using reactive Spring Cloud Gateway. With the new feature, I expect to be able to register the following bean:

	@Bean
	public TokenExchangeReactiveOAuth2AuthorizedClientProvider tokenExchange(
			ReactiveClientRegistrationRepository clientRegistrationRepository,
			ServerOAuth2AuthorizedClientRepository authorizedClientRepository) {

		TokenExchangeReactiveOAuth2AuthorizedClientProvider authorizedClientProvider =
				new TokenExchangeReactiveOAuth2AuthorizedClientProvider();
		authorizedClientProvider.setSubjectTokenResolver(...);

		return authorizedClientProvider;
	}

and have this picked up by Spring Security and wired into the default instance of ReactiveOAuth2AuthorizedClientManager, thus enabling the Token Exchange grant type. Instead, it isn't picked up and the token exchange flow fails due to missing support for the Token Exchange grant type.

To use Spring Security's provided ReactiveOAuth2AuthorizedClientManager (as a workaround), applications can include:

@EnableAutoConfiguration(exclude = GatewayReactiveOAuth2AutoConfiguration.class)

However, this isn't straight-forward and requires some advanced knowledge to troubleshoot why Spring Security's default isn't being provided.

Alternatively, applications can register their own ReactiveOAuth2AuthorizedClientManager bean to override auto-configuration. This isn't ideal since the solution isn't able to take advantage of the simplified configuration feature in Spring Security.

Note: I can make the sample repository available shortly if a reproducer is needed.

@sjohnr
Copy link
Contributor Author

sjohnr commented Aug 12, 2024

I should mention, I have not yet checked to see if a similar issue exists for MVC gateway.

@sjohnr
Copy link
Contributor Author

sjohnr commented Sep 12, 2024

@spencergibb any thoughts on this one?

@spencergibb
Copy link
Member

I think it sounds good.

@sjohnr
Copy link
Contributor Author

sjohnr commented Sep 12, 2024

Thanks. Do we also have a similar issue on the MVC gateway?

sjohnr added a commit to sjohnr/spring-cloud-gateway that referenced this issue Sep 18, 2024
@sjohnr
Copy link
Contributor Author

sjohnr commented Sep 18, 2024

@spencergibb I opened gh-3528 to remove the auto-config. I did not find any auto-configuration for the mvc gateway.

As a side note, I would also like to work on equivalent support for providing a custom registrationId for the mvc gateway's tokenRelay() as we have added in reactive gateway. I'll open an issue for that.

@spencergibb spencergibb added this to the 4.2.0-M2 milestone Sep 25, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in 2024.0.0-M2 Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants