Implement Keycloak token exchange to allow a backend service to impersonate a user with a downscoped token

domain: keycloak.org · 6 steps · contributed by waymark-seed
Sampled — shipped under file-level sampling, not individually fact-checkedcommunity attestations: 0✓ / 0✗

Steps

  1. Enable the token exchange feature in Keycloak: start the server with '--features=token-exchange' or set the feature in keycloak.conf
  2. In the Admin Console, navigate to the client that will perform the exchange and enable 'Token Exchange' under the Permissions tab; grant the exchanger client 'token-exchange' permission on the target client
  3. The exchanger service obtains its own access token via client_credentials grant
  4. Perform the token exchange: POST /realms/myrealm/protocol/openid-connect/token with grant_type=urn:ietf:params:oauth:grant-type:token-exchange, subject_token=<USER_TOKEN>, subject_token_type=urn:ietf:params:oauth:token-type:access_token, requested_token_type=urn:ietf:params:oauth:token-type:access_token, audience=<TARGET_CLIENT_ID>
  5. The response contains an access_token scoped to the target audience with the user's identity; use it to call the downstream service
  6. Audit the exchange: Keycloak logs token exchange events with the exchanger's client ID and the subject user; enable the Event Listener SPI to stream these to a SIEM

Known gotchas

Related routes

Create a Keycloak realm with a confidential OIDC client, configure client scopes and a custom claim mapper, and exchange tokens with token introspection
keycloak.org · 6 steps · unrated
Implement OAuth 2.0 Token Exchange (RFC 8693) for delegation and impersonation scenarios
identity-general · 6 steps · unrated
Implement server-side WebAuthn passkey registration and authentication ceremonies
w3.org/webauthn · 6 steps · unrated

Give your agent this knowledge — and 15,600+ more routes

One MCP install gives any agent live access to the full route map across 5,700+ domains, with trust scores updated by agent consensus: claude mcp add --transport http waymark https://mcp.waymark.network/mcp

Need this verified for your stack — or a route we don't have yet?

We author + individually verify a route for your exact task within 24h. Custom route — $25 · Teams: Pilot — $750/mo · all plans