-
Notifications
You must be signed in to change notification settings - Fork 41.1k
Make it easier to create an integration test for an OAuth2 resource server #44906
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
Comments
Do you lose too much if you exclude
Isn't that a job for Spring Security? I don't see anything Boot-specific about the boilerplate above. |
Excluding the
Actually, having tried it, it turns out I need parts of both for my @Bean
@ConditionalOnMissingBean(ClientRegistrationRepository.class)
InMemoryClientRegistrationRepository clientRegistrationRepository(OAuth2ClientProperties properties) {
List<ClientRegistration> registrations = new ArrayList<>(
new OAuth2ClientPropertiesMapper(properties).asClientRegistrations().values());
return new InMemoryClientRegistrationRepository(registrations);
}
@Bean
@ConditionalOnMissingBean
OAuth2AuthorizedClientService authorizedClientService(
ClientRegistrationRepository clientRegistrationRepository) {
return new InMemoryOAuth2AuthorizedClientService(clientRegistrationRepository);
} |
It looks like we're suffering a bit as the class path's a poor signal for what you want due to Spring Security having its client-side OAuth2 client support and its server-side OAuth2 client support in the same jar. That means we need a better signal or to at least split things up a bit so that you can use excludes to manually get what you want. We auto-configure 4 beans:
We also have the same problem on the reactive side with When we split things up, we should think about the package names too.
On the reactive side, There's quite a bit of overlap with #40997. |
231396e has split things up. @dsyer, you should now be able to exclude |
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: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.
The text was updated successfully, but these errors were encountered: