Lab: Live OAuth flows with Keycloak

Run a real authorization code and client credentials flow. Keycloak is standing in for Microsoft Entra ID.

Identity provider Keycloak — simulating Microsoft Entra ID
Callback server Node.js — handles the token exchange server-side

Flow 1: Authorization code grant

This flow lets a user log in and consent. Keycloak authenticates you, issues an authorization code, and your browser delivers it to the callback server — which exchanges it for tokens server-side. You will receive both an ID token (proving who you are) and an access token (for calling APIs).

Tokens received

ID token  — for your app, proves who logged in ID Token

Raw token (never send this to an API):

Decoded claims:

Access token  — for the API, not for your app to decode Access Token

Raw token (send this in Authorization: Bearer …):

Decoded claims (if JWT):

Flow 2: Client credentials grant

This flow has no user. The callback server authenticates as itself using its client_id and client_secret, and receives an access token it can use to call APIs on its own behalf. The secret never touches the browser.

Token received

Access token  — no user, issued to the client itself Access Token

Decoded claims (if JWT):

What you just saw

Audience — every token is addressed to a specific recipient. The ID token's aud claim contains your client_id; the access token's aud is the API it's meant for. Presenting a token to the wrong audience will be rejected.
Bearer tokens — whoever holds the token can use it. That's why the access token travels from the callback server to your browser over a local redirect, and why you should never log or expose it beyond what's needed.
ID token vs. access token — your app reads the ID token to know who logged in. The access token goes to the API in an Authorization: Bearer … header. They are not interchangeable.

← Back to course home