Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backend to backend communication through REST with Keycloak protected backends

Tags:

keycloak

I have two webapps. Each has frontend(AngularJS) and backend(Java). Each frontend has it's own public access type configuration keycloak.json file. Each backend has it's own bearer-only access type configuration keycloak.json file. Each frontend app is working fine with it's own backend. My task is make REST call to each other(backend to backend). How could I achieve that? Because on each backend REST sevices are protected by checking token validity.

like image 328
Eazy Avatar asked Nov 04 '16 08:11

Eazy


1 Answers

If all those backend services are secured by keycloak, look at KeycloakRestTemplate extension of RestTemplate in Spring keycloak adapter. KeycloakRestTemplate is imported as part of keycloak-spring-security-adapter jar dependency.

Basically, it uses KeycloakClientRequestFactory and internally, adds Authorization header (for currently authenticated principal) to all requests for service to service calls.

https://github.com/keycloak/keycloak/blob/master/adapters/oidc/spring-security/src/main/java/org/keycloak/adapters/springsecurity/client/KeycloakRestTemplate.java

like image 190
Jas Bali Avatar answered Oct 31 '22 19:10

Jas Bali