Repository navigation
Issue with Linking Social Account to an Existing Keycloak User #38615
Replies: 1 comment
|
Hi @Andruxa36rus, I dug into this properly since a few people are running into the same thing. What you're seeing on Keycloak 26.0.8 is mostly a legacy-flow mismatch, not a social-email mismatch. The Code path in 26.0.8:
So passing an access token or ID token into Worth noting: from Keycloak 25+, If you must stay on 26.0.8 legacy flow, capture the session identifier from the token endpoint response ( Also, legacy linking requires an active browser SSO cookie session and proper account-link permissions ( The legacy endpoint is deprecated in current versions (AIA
On your specific questions:
Different email is fine. Linking goes off the authenticated Keycloak user + broker identity, not email equality.
Prefer not using legacy flow now. If you must use it, use the real user session ID from the same active browser SSO session (identity cookie session). |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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 thesession_stateparameter. However, this parameter is missing in OpenID tokens and is not returned in responses fromintrospect.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_stateis necessary for generating thehash. However, in the current versions of Keycloak, this parameter is unavailable.Steps to Reproduce
/broker/{provider}/link.access_tokenusingdecode_token()inpython-keycloak.session_stateparameter is missing.introspect(), butsession_state(orsid) is also missing there.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
session_stateorsidfor generating a social account linking URL.introspect()oradmin API.KEYCLOAK_IDENTITYand how to format it correctly.Actual Behavior
session_stateis missing fromaccess_token,id_token, andintrospect()./users/{user_id}/sessionsviaadmin APIalso does not returnsession_state.KEYCLOAK_IDENTITY = access_tokenresults inFailed to verify identity token.Environment
Questions
session_stateorsidfor linking a social account?All reactions