问题
I have two services registered as two keycloak clients in the same realm. Access type of both the clients is set to public in keycloak client settings.
Both the services works fine when we try to login via Keycloak.
After login to first(service-1) user does some operation, for which I need to make a REST call to (service-2). Now If I try to do a REST call from one service to other, It redirects to HTML and returns some HTML response instead of actual response.
What is the Way I can make calls between these two services.
回答1:
To communicate to an api protected via keycloak you need to provide authorization. For that all you need to do is pass the access token in the authorization header.
To get this token you can make a login call, get the access token and pass that along or you can make use of the token passed to access to first service itself.
回答2:
No it is not possible yet because this issue https://issues.jboss.org/plugins/servlet/mobile#issue/KEYCLOAK-6073. In summary you cannot use the token generated by the login web page in the backed calls unless you use the same keycloak URL in both cases.
来源:https://stackoverflow.com/questions/51835334/communication-between-two-micro-services-keycloak-clients