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

Make it easier to create an integration test for an OAuth2 resource server #44906

Open
dsyer opened this issue Mar 26, 2025 · 0 comments
Open
Labels
status: waiting-for-triage An issue we've not yet triaged

Comments

@dsyer
Copy link
Member

dsyer commented Mar 26, 2025

If you want to integration test a resource server you need the OAuth2 client, but when you add that (even just in test scope) it changes the security configuration of a Spring Boot application by default - it is no longer a resource server, but instead it becomes an OAuth2 client (and installs an OAuth2 login filter instead of the resource server filter).

Also, it's kind of a pain to set up a RestClient with a bearer token for the test. You have to create an interceptor. With client credentials it looks like this:

@Bean
@Lazy
public RestClient personService(RestClient.Builder builder, ClientRegistrationRepository repository,
		OAuth2AuthorizedClientService service,
		@Value("http://localhost:${local.server.port:8080}") String url) {
	AuthorizedClientServiceOAuth2AuthorizedClientManager manager = new AuthorizedClientServiceOAuth2AuthorizedClientManager(
			repository, service);
	OAuth2ClientHttpRequestInterceptor interceptor = new OAuth2ClientHttpRequestInterceptor(manager);
	interceptor.setClientRegistrationIdResolver(request -> "spring");
	builder.baseUrl(url).requestInterceptor(interceptor);
	return builder.build();
}

Ideally we'd like a way to tell Spring Boot that to set that stuff up: 1) switch off the OAuth2SecurityFilterChainConfiguration (currently not visible and not an independent autoconfig, so you can't actually exclude it); 2) make it easier to create an HTTP client.

Sort of related to #43978 but this is for a webapp that is itself a resource server.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

No branches or pull requests

2 participants