Keycloak Version
Keycloak 26.0.8 (Docker)
Description
When attempting to generate a link for associating a social account with an existing Keycloak user using /realms/{realm}/broker/{provider}/link, the Keycloak API requires the session_state parameter. However, this parameter is missing in OpenID tokens and is not returned in responses from introspect.
In my case the user on the social network has a different email.
Documentation and code samples (including Java code in the official documentation) indicate that session_state is necessary for generating the hash. However, in the current versions of Keycloak, this parameter is unavailable.
Steps to Reproduce
- A user is already registered in Keycloak.
- We need to generate a link to associate a social account using
/broker/{provider}/link. - Decode the user’s
access_tokenusingdecode_token()inpython-keycloak. - The
session_stateparameter is missing. - Use
introspect(), butsession_state(orsid) is also missing there. - Attempt to pass
id_tokenoraccess_tokenin theKEYCLOAK_IDENTITYcookie, but Keycloak rejects the tokens with errors likeExpected '[Serialized-ID]' but was 'Bearer'orExpected '[Serialized-ID]' but was 'ID'.
Expected Behavior
- The Keycloak API should provide
session_stateorsidfor generating a social account linking URL. - There should be a way to retrieve this parameter via
introspect()oradmin API. - Clear documentation should explain which token should be used in
KEYCLOAK_IDENTITYand how to format it correctly.
Actual Behavior
session_stateis missing fromaccess_token,id_token, andintrospect().- A request to
/users/{user_id}/sessionsviaadmin APIalso does not returnsession_state. - Setting
KEYCLOAK_IDENTITY = access_tokenresults inFailed to verify identity token.
Environment
- Keycloak 26.0.8
- python-keycloak 4.6.2
- Python 3.8.10
Questions
- How can I use this link to link a user to a social network?
- How can we retrieve
session_stateorsidfor linking a social account? - What about Cookies?
- What are the alternative ways to link a social network to an existing user with different emails?