Lion Cipher Lab

Delegate without handing over the keys: OAuth 2.0 Token Exchange (RFC 8693) in Keycloak

Why it matters

Almost every real system is a chain, not a single hop. A user logs into a web app; the web app calls an orders API; the orders API needs to ask a billing API something. The user's access token — the small credential that proves 'this request is allowed' — arrives at the orders API, and now a developer has to decide what to send onwards. Two answers come naturally and both are quietly dangerous. The first is to FORWARD the same token: cheap, works immediately, and it means the billing API now holds a credential that also opens the orders API, the reporting API, and anything else that token was…

What you'll learn

Steps in this lab

  1. The problem, before any of the vocabulary
  2. The vocabulary of an exchange: subject, actor, delegation, impersonation
  3. When NOT to exchange (read this before you build anything)
  4. Version reality check: two token exchanges live in Keycloak, and they are not the same
  5. Check your tools, then start Keycloak on a pinned image
  6. Build the three-service world: one realm, three clients, one user
  7. Wire the audiences — and learn why the audience parameter filters instead of adds
  8. Set up your shell and get the user's token (the subject token)
  9. Perform the exchange with curl
  10. Diff the two tokens — this is the whole lesson in four claims
  11. Break it on purpose, twice: watch the exchange get refused
  12. Where is the act claim? Spec versus implementation, honestly
  13. The pro move: combine narrowing with sender-constraining
  14. Tear it down

Open the full interactive lab →