-
Notifications
You must be signed in to change notification settings - Fork 244
Ribbon support to contact the auth server #61
Comments
I agree that might be cool, when the auth server is a registered service. Contributions gladly accepted. Note (for anyone attempting a pull request): the |
We have the same situation for property security.oauth2.resource.userInfoUri. In this case wouldn't it be enough to inject the DiscoveryClient into org.springframework.boot.autoconfigure.security.oauth2.resource.UserInfoTokenServices? If a DiscoveryClient is available we use it to resolve the userinfo service uri. Something like this: public UserInfoTokenServices(String userInfoEndpointUrl, String clientId, DiscoveryClient discoveryClient){
String uri = discoveryClient.getInstances(userInfoEndpointUrl).get(0).getUri().toString();
this.userInfoEndpointUrl = uri;
this.clientId = clientId;
} If that is enough I would enhance the UserInfoTokenServices and configuration classes. |
That won't work in quite that form because |
Didn't saw that UserInfoTokenServices is from spring-boot-autoconfigure. Never develop in a text editor, sorry. So you mean you would enhance spring-cloud-security. Does that mean you would provide alternative configurations, exclude original configurations from spring-boot-autoconfigure and provide some alternative implementations. Do you have some recommendation how we could start to solve this? |
We solved it now with the UserInfoRestTemplateCustomizer. It workes great for us: @Override
public void customize(OAuth2RestTemplate template) {
template.setRequestFactory(ribbonClientHttpRequestFactory);
} |
@huningd good catch. However that is not enough to also support You can do that thing (ATTENTION not heavily tested and only tested with authorization-code mode, copy at your own risk) CAMDEN VERSION (you should use bean @Bean
UserInfoRestTemplateCustomizer oauth2RestTemplateCustomizer(RetryLoadBalancerInterceptor interceptor) {
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
interceptors.add(interceptor);
return template -> {
AccessTokenProviderChain accessTokenProviderChain = Stream
.of(new AuthorizationCodeAccessTokenProvider(), new ImplicitAccessTokenProvider(),
new ResourceOwnerPasswordAccessTokenProvider(), new ClientCredentialsAccessTokenProvider())
.peek(tp -> tp.setInterceptors(interceptors))
.collect(Collectors.collectingAndThen(Collectors.toList(), AccessTokenProviderChain::new));
template.setAccessTokenProvider(accessTokenProviderChain);
};
} BRIXTON VERSION @Bean
UserInfoRestTemplateCustomizer userInfoRestTemplateCustomizer(SpringClientFactory springClientFactory) {
return template -> {
AccessTokenProviderChain accessTokenProviderChain = Stream
.of(new AuthorizationCodeAccessTokenProvider(), new ImplicitAccessTokenProvider(),
new ResourceOwnerPasswordAccessTokenProvider(), new ClientCredentialsAccessTokenProvider())
.peek(tp -> tp.setRequestFactory(new RibbonClientHttpRequestFactory(springClientFactory)))
.collect(Collectors.collectingAndThen(Collectors.toList(), AccessTokenProviderChain::new));
template.setAccessTokenProvider(accessTokenProviderChain);
};
} With that
where It can be a partial response for #94 we just need a trick for |
@kakawait |
@skyding1212 sorry but I've just upgraded my project to |
@skyding1212 I had the same problem with Dalston. But sulution providen by @kakawait work fine(that was for CAMDEN version) with dependency solved all problems!
|
@skyding1212 As I said
So you need to autowired @Bean
UserInfoRestTemplateCustomizer userInfoRestTemplateCustomizer(LoadBalancerInterceptor loadBalancerInterceptor) {
return template -> {
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
interceptors.add(loadBalancerInterceptor);
AccessTokenProviderChain accessTokenProviderChain = Stream
.of(new AuthorizationCodeAccessTokenProvider(), new ImplicitAccessTokenProvider(),
new ResourceOwnerPasswordAccessTokenProvider(), new ClientCredentialsAccessTokenProvider())
.peek(tp -> tp.setInterceptors(interceptors))
.collect(Collectors.collectingAndThen(Collectors.toList(), AccessTokenProviderChain::new));
template.setAccessTokenProvider(accessTokenProviderChain);
};
} Or add dependencies as @alexandr-efimov explained above Sample was updated to |
Any progress on that? |
1 similar comment
Any progress on that? |
No there hasn't. If there is, we will update the issue. |
@dsyer on your first response of this issue you said that "The accessTokenUri is used in a back channel inside the OAuth2RestTemplate, so it will also be fiddly (but not impossible) to override the nested RestTemplate used for that call." This is exactly what is happening even in Spring Cloud Edward.SR2... Is there any way that you can think on how eureka instanceId could be used for access-token-uri? |
it will errror when jwt token is expired and need to refresh . |
it should be ribbon issue, because it only refresh token fail with the load balance inteceptor |
I have encountered a similar problem with authentication server name resolution. I will describe how I solved it. application.properties
Pay attention to Configure RestTemplate to use the Ribbon functionality:
this configurator will work for all RestTemplate instances: RestTemplate, OAuth2RestTemplate, etc. Now we need to force RemoteTokenServices to use our RestTemplate instance.
And that's all.The short sequence will be as follows:
When a POST request is sent to |
@dsyer I've just been looking at how to resolve this issue for myself and been thinking about your very first comment re the browser There have already been a few posts above that highlight how to take care of the other redirect issues so if you agree with this kind of approach I've suggested I can have a look at putting a PR together that would cover it. |
I have tried all the solutions mentioned above and NONE!!! of them work. This is a major flaw in Spring since now a days with discovery services almost becoming standard it should be working. Does anybody know what the status of this is? |
Anybody knows when would the PR #1523 be merged? |
That is not a valid PR# can you provide a link? |
Why don’t you comment on that PR and ask? |
It works to me. Thaks. |
it would be great if I could replace
localhost:9999
with the name of the eureka service idThe text was updated successfully, but these errors were encountered: