4
votes

I have a secured micro service that is calling another secured micro service. Both services have service accounts in Keycloak. How can I configure the 1st service to automatically obtain access token from keycloak when calling the 2nd service? It's a simple service to service communication. Does the Quarkus Rest client have an API to do this? If not, how can I do that with the vert.x rest client?

1
In Spring Security that would be org.springframework.security.oauth2.client.OAuth2RestTemplate - overthetop
I thought that the token would be passed automatically to the rest client by microprofile definition. If that's not the case, then you should inject your token via @ClientHeaderParam(name = "Authorization", value = "{token}") in your rest client. - Serkan
Yes @Serkan you can pass the token that way. I've end up using the vertx stuff because of the oauth2 providers and the ease of use for the web client. - overthetop
It seems like this is currently an open Quarkus issue: Implement token propagation in the REST client. You may want to keep an eye on it. - Steve C

1 Answers

3
votes

I was able to make this work by extending the javax.ws.rs.client.ClientRequestFilter. Unfortunately I had to write my own OAuth2 logic in order to manage the access token between the requests. I hope that in the future Quarkus would provide an alternative to org.springframework.security.oauth2.client.OAuth2RestTemplate