-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Using RestTemplate to access ZuulProxy resources #81
Comments
yes it would be nice if we have a more elaborated example for this use case. |
I'll publish something to github. (this is part of a production app so I'll try to create a skeleton structure) Here's already an overview (calls to the auth server have been omitted... we assume we are dealing with a logged-in user (Oauth2Authentication is tied to the http session).
ATM, the idea is that everything is accessed via the gateway component (various javascript UIs / resource servers). Everything is secured using oauth2 (SSO). The resource servers accept bearer tokens but as everything needs to be access via the gateway the architecture relies heavily on http sessions.
|
we need to think about load balancing ribbon or so; talking directly to a resource (step5) will be a bad idea. or does ribbon talk to eureka and not to resource component!!!!! i would love to work on a side (ready to deploy) project. |
I'd be happy to go via the GW but have no idea how to make the rest call from resource1 ---> GW ---> resource2. |
@zirconias I've added a sample in this github repo in sample2 The resource2 backend service calls the resource1 backend service with the following code Although i can acces the OAuth2Authentication, I cannot extract the oauth2 key, and if I want to pass through the gateway I need to have the correct JSESSIONID. In this backend call I don't have an easy access to this session. Current workaround
It works, but there has to be a better way.
|
@ddewaele I am facing the same scenario with the same problem, communication between resources through zuul gateway, did you find any solution other than getting JSESSIONID cookie. |
I am in the similar boat. I have OAuth2 server, Zuul Proxy server(UI Application) and a Microservice(CatalogService). From Zuul Proxy I am able to invoke CatalogService endpoint using OAuth2RestTemplate which propagates OAuth Token. //This is working fine But, when I configure CatalogService in Zuul routes as follows:
and try to invoke CatalogService endpoint thru Zuul Proxy it is redirecting to Login page. //This is NOT working One more observation is if I invoke the same REST endpoint (http://localhost:8080/api/catalog/products) via AJAX using jQuery from Zuul Proxy (UI app)it is working fine. I will most likely use Eureka Discovery and invoke it like http://catalog-service/api/catalog/products which might work. But I would like to know why calling catalog-service via Zuul Proxy URL with OAuth2RestTemplate is not working. My understanding is, after authentication OAuth2RestTemplate should include auth token even for invoking REST endpoints on same Zuul proxy server. Any thoughts? |
@sivaprasadreddy I'm not sure you are describing the same problem. I wouldn't expect your use case to work without setting the sensitive headers (per the user guide). |
@dsyer I have set zuul.sensitiveHeaders=(blank) which should send all headers. In case you want to take a look at my code here is the repo https://github.com/sivaprasadreddy/spring-security-oauth2-demo. The problem i am describing is here https://github.com/sivaprasadreddy/spring-security-oauth2-demo/blob/master/ui-zuul-app/src/main/java/com/sivalabs/uizuulapp/HomeController.java.
This is returning Login page html as response. |
The way I understand it, if you have a gateway component with a
@EnableZuulProxy
and@EnableOAuth2Sso
annotation it is able to proxy requests to Oauth2 protected backends bySo with the following zuul rules
I can access (@EnableResourceServer) backends directly (outside of Zuul) with a valid access token :
And I can access the same backend through Zuul providing I have a valid JSESSION ID that Spring can use to extract the OAuth2Authentication / Access token
Now suppose I have the following flow
The server-side code in /backend can call /backend2 via Zuul but it needs to know the JSESSIONID.
By default RestTemplate doesn't send cookies so /backend2 gets called without a valid JESSIONID and it is unable to authenticate the request.
What would be the proper way to solve this ? The /ui would be able to call /backend2 just fine via javascript / REST (as it has a valid session in the browser). But how would a backend component call /backend2 ? I don't want to rely on too many hacks to extract the JSessionID from the original request and sending it as a cookie / header value. Perhaps using RestTemplate isn't the way to go ?
The text was updated successfully, but these errors were encountered: