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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With