I'm allowing users logged in an external application to jump into our application with their access token through Keycloak's identity brokering and external to internal token exchange.
Now I'd like to establish an SSO session in an embedded JxBrowser in our application similar to a regular browser login flow, where three cookies are set in the browser: AUTH_SESSION, KEYCLOAK_SESSION(_LEGACY) and KEYCLOAK_IDENTITY(_LEGACY).
KEYCLOAK_IDENTITY contains a token of type Serialized-ID
which looks somewhat similar to an ID token.
Is it possible to create the KEYCLOAK_IDENTITY cookie using the exchanged (internal) access and/or ID token and, provided that the other two cookies are correctly created as well, would this establish a valid SSO session?
Basically all I am missing is how I could obtain or create the Serialized-ID
type token.
One way to achieve this:
Note that the provider works fine for me without registering it in
standalone.xml
, I'm just adding the JAR to the Keycloak Docker image.Add a method that validates a given access token, looks up the user, gets the user session and sets the cookies in the response (most error handling omitted for brevity):
Disclaimer: I am not completely certain this implementation does not imply any security issues, but since
Tokens.getAccessToken(accessToken, keycloakSession)
does full validation of the access token, setting the cookies should only be possible with a valid access token.For CORS, add:
and in
sso()
:What I am uncertain about is why Firefox preflights the
GET
request, making it necessary to handle that.