BACKGROUND:
There are several services (spring boot REST API services and some other productions with REST API) as back-end and some angular applications (some web site with different second-level domain name) as front-end.
One front-end application can call some back-end services using asynchronous method (they are under the same domain by reversed proxy, so no CORS problems).
TARGET
SSO, viz. if a user logs into a front-end application successfully, the user should access other applications without login again. (Of course, in the same browser with cookie enabled)
QUESTIONS
- Should REST API follow Client Credentials Flow (return 401 if not authenticated) or Authentication Code Flow (return 302 if not authenticated) ?
Many documents/tips/posts suggest REST API should follow Client Credentials Flow because it is stateless and do not know the redirect uri. However, if I'm not wrong, it is impossible to implement OSS using Client Credentials Flow otherwise all back-end services should be the same client in keycloak which could share client_id and client_secret.
If using Authentication Code Flow, the problem is how the front-end could retrieve response data after a user successfully logs in. The process is something like:
front-end back-end keycloak
| -- asyn call --> |
| <-- HTTP 302 -- |
| -- redirect to login page --> |
| <-- redirect to where ???-- |
If the answer to question 1 is following Client Credentials Flow, then is it the best practice to share the same
client_idandclient_secretbetween several back-end services? Or are there any other solutions?If the answer to question 2 is following Authentication Code Flow, then how to handle the asynchronous REST API calls after successfully log in?