Our stack includes the following services, each service runs in a docker container:
- Front-end in React
- Backend service based on Spring boot "resource-service"
- Keycloak
- Other backend service (consumer)
Both the front-end and the consumer services communicate with the backend using REST API. We use Keycloak as our user management and authentication service.
We would like to integrate our Spring based service "resource-service" with Keycloak by serving both web application and a service flows:
Web application - React based front-send that should get a redirect 302 from the "resource-service" and send the user / browser to login in the Keycloak site and then return to get the requested resource.
Server 2 Server coomunication - A server that need to use the "resource-service" API's should get 401 in case of authentication issues and not a redirection / login page.
There are few options to integrate Spring with Keycloak:
- Keycloak Spring Boot Adapter
- Keycloak Spring Security Adapter
- Spring Security and OAuth2
I noticed that there is a "autodetect-bearer-only" in Keycloak documentation, that seems to support exactly that case. But - There are a lot of integration options and I'm not sure what is the best way to go, for a new Spring boot service. In addition, I didn't find where to configure that property.