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_token
usingdecode_token()
inpython-keycloak
. - The
session_state
parameter is missing. - Use
introspect()
, butsession_state
(orsid
) is also missing there. - Attempt to pass
id_token
oraccess_token
in theKEYCLOAK_IDENTITY
cookie, 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_state
orsid
for 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_IDENTITY
and how to format it correctly.
Actual Behavior
session_state
is missing fromaccess_token
,id_token
, andintrospect()
.- A request to
/users/{user_id}/sessions
viaadmin API
also does not returnsession_state
. - Setting
KEYCLOAK_IDENTITY = access_token
results 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_state
orsid
for linking a social account? - What about Cookies?
- What are the alternative ways to link a social network to an existing user with different emails?