-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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 RestTemplate used by ClientRegistrations (Discovery) configurable #7027
Comments
We usually use org.springframework.boot.web.client.RestTemplateBuilder to achieve this in our code, but I can not immediately tell if that would be a valid approach in the spring-security project. If so: |
FYI: Found 6 more occurences of new RestTemplate() that will also be affected and unconfigurable, 2 of them in spring-security-oauth2-client. We stumbled upon this because the RestTemplate() will try to use the host/port of a proxy that is configured via environment variables, but ignores the user and password. Complete list:
I'll think about a solution for this over the weekend, to write a pull request. For now I only had bad ideas that even I dont like. |
#5607 is related, I think. |
@shibuyaku Instead of using OpenID Connect Discovery via Also see the reference doc. As far as allowing a configurable |
Thanks for the input. We got it running with your solution, without OIDC discovery. |
Same case https://stackoverflow.com/q/58495332/206466 I think, I need to customize it for debugging what's going wrong. I'm not sure what @jgrandja describes works in my use case... I certainly don't understand it well enough to implement. could we just have a customizer for this instead of having to reimplement all the services, especially since they are final and can't be extended? |
@Budlee |
@xenoterracide I took a look at your SO question. You can supply a custom Current @Bean
OAuth2AuthorizedClientManager authorizedClientManager(
ClientRegistrationRepository clientRegistrationRepository,
OAuth2AuthorizedClientRepository authorizedClientRepository) {
OAuth2AuthorizedClientProvider authorizedClientProvider =
OAuth2AuthorizedClientProviderBuilder.builder()
.clientCredentials()
.build();
DefaultOAuth2AuthorizedClientManager authorizedClientManager =
new DefaultOAuth2AuthorizedClientManager(
clientRegistrationRepository, authorizedClientRepository);
authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);
return authorizedClientManager;
} Updated @Bean
OAuth2AuthorizedClientManager authorizedClientManager(
ClientRegistrationRepository clientRegistrationRepository,
OAuth2AuthorizedClientRepository authorizedClientRepository) {
OAuth2AuthorizedClientProvider authorizedClientProvider =
OAuth2AuthorizedClientProviderBuilder.builder()
.clientCredentials(configurer ->
configurer.accessTokenResponseClient(clientCredentialsTokenResponseClient()))
.build();
DefaultOAuth2AuthorizedClientManager authorizedClientManager =
new DefaultOAuth2AuthorizedClientManager(
clientRegistrationRepository, authorizedClientRepository);
authorizedClientManager.setAuthorizedClientProvider(authorizedClientProvider);
return authorizedClientManager;
}
private OAuth2AccessTokenResponseClient<OAuth2ClientCredentialsGrantRequest> clientCredentialsTokenResponseClient() {
RestOperations accessTokenClient = null; // TODO Configure
DefaultClientCredentialsTokenResponseClient clientCredentialsTokenResponseClient = new DefaultClientCredentialsTokenResponseClient();
clientCredentialsTokenResponseClient.setRestOperations(accessTokenClient);
return clientCredentialsTokenResponseClient;
} |
ok, but it'd be nice to be able to just |
@xenoterracide We have an open ticket for this #5607 |
Thanks, I only found this one |
Just hit this issue myself in our corporate environment. Because of this line I'll have to duplicate all the nice provided functionality using an http client configured with our proxy. Will be watching this issue with interest. |
Came across this issue aswell since we are using a corporate proxy and OIDC Discovery was ignoring the proxy username and password provided via system properties (-Dhttp.* and -Dhttps.*) during startup. Disabled Discovery for now and using static uri's in provider configuration. |
Closing in favour of #8882. Please see ClientRegistrations and provide any additional feedback there. |
Summary
spring-security-oauth2-client uses a RestTemplate for openid/oauth Discovery that is not configurable. This is unuseable in scenarios where you need to adjust the RestTemplate. Example: You need to use a proxy and configure auth.
Actual Behavior
ClientRegistrations class uses a RestTemplate for doing OpenId Discovery that is not configurable, since it is not using RestTemplateBuilder or something comparable.
OpenId discovery is done by querying issuerUri + "/.well-known/openid-configuration" (for oidc) or isserUri + "/.well-known/oauth-authorization-server" (for oauth).
Current implementation:
RestTemplate rest = new RestTemplate()
Expected Behavior
ClientRegistrations should use a configurable RestTemplate for doing OpenId Discovery. One should be able to configure the requestFactory, interceptors, errorHandler and so on of that RestTemplate.
Configuration
Version
5.2.0.M3 and 5.1.5.RELEASE
Sample
spring-security/oauth2/oauth2-client/src/main/java/org/springframework/security/oauth2/client/registration/ClientRegistrations.java
Line 58 in 1739ef8
Related #5607
The text was updated successfully, but these errors were encountered: