Antonio Braccolino, Identity & Access, home
EN · Language: English

IAM interview questions · Protocols

Walk me through the authorization code flow with PKCE.

In plain wordsThe dry cleaner gives you half of a torn ticket: only the person with the matching half can collect the coat.

How it works

The client creates a random code_verifier and sends its SHA-256 hash (code_challenge) in the authorization request, together with state and, for OIDC, nonce. The user authenticates at the IdP, which returns a short-lived, one-time code to the registered redirect_uri.

The client checks state, then calls the token endpoint over the back channel with the code and the original verifier. The IdP hashes the verifier and compares it to the stored challenge: only the party that started the flow can finish it.

PKCE was designed for mobile and SPAs that cannot keep a client secret, but OAuth 2.1 and current best practice require it for all clients, confidential ones included. The implicit flow is deprecated.

See it in action

Authorization code flow with PKCE, step by step

The flow you will be asked to “walk me through” in almost every protocol interview. Watch where the secret is created and where it is checked.

  1. Browserthe user
  2. Appthe OAuth client
  3. IdPauthorization server
  4. APIresource server
  1. Step 1 of 8 · App

    The app invents a secret

    In plain words Before anything else the app creates a random secret and keeps it. It sends out only a “fingerprint” of it.

    In the interview, call it code_verifier, code_challenge (S256)

    Technical details

    code_challenge = BASE64URL(SHA-256(code_verifier)). The app also creates state (against CSRF) and nonce (against ID token replay).

  2. Step 2 of 8 · App → Browser

    The app sends the user to the IdP

    In plain words The browser is redirected to the login page, carrying the fingerprint, the app’s name and what it wants to do.

    In the interview, call it Authorization request

    Technical details

    /authorize?response_type=code&client_id=…&redirect_uri=…&scope=openid profile&state=…&nonce=…&code_challenge=…&code_challenge_method=S256

  3. Step 3 of 8 · Browser → IdP

    The user logs in at the IdP

    In plain words The password is typed only on the IdP’s page, never in the app. The IdP remembers the fingerprint.

    In the interview, call it Authentication at the authorization server

    Technical details

    The IdP checks that redirect_uri exactly matches a registered value, authenticates the user, asks consent if needed and stores the challenge with the code.

  4. Step 4 of 8 · IdP → App

    A short-lived code comes back

    In plain words The IdP gives back a one-time code through the browser. The code alone is not enough: anyone could have seen it.

    In the interview, call it Authorization code, front channel

    Technical details

    The app checks that state matches what it sent. The code travels in the URL, so it can leak through logs, history or a malicious app.

  5. Step 5 of 8 · App → IdP

    The app proves it started the login

    In plain words The app sends the code together with the original secret. The IdP computes the fingerprint and compares it.

    In the interview, call it Token request, back channel, PKCE check

    Technical details

    SHA-256(code_verifier) must equal the stored code_challenge. An attacker with a stolen code does not have the verifier, so the exchange fails.

  6. Step 6 of 8 · IdP → App

    The tokens arrive

    In plain words The ID token tells the app who logged in. The access token is the ticket for the API.

    In the interview, call it Token response

    Technical details

    The app validates the ID token: signature via JWKS, iss, aud = its client_id, exp, and nonce. It must never send the ID token to an API.

  7. Step 7 of 8 · App → API

    The app calls the API

    In plain words The app shows the ticket. The API checks it was printed by the IdP, for this API, and is still valid.

    In the interview, call it Access token validation, audience, scopes

    Technical details

    Validate signature (cached JWKS, pinned alg), iss, aud, exp/nbf, then scopes for coarse permission and your own rules for object-level access.

  8. Step 8 of 8 · App → IdP

    An hour later: a fresh ticket

    In plain words The ticket expires quickly on purpose. The app swaps a refresh token for a new one, and the old refresh token stops working.

    In the interview, call it Refresh token rotation, reuse detection

    Technical details

    If an old refresh token is presented again, the IdP assumes theft and revokes the whole token family.

A concrete example

On Android a malicious app registers the same custom URL scheme (myapp://callback) and receives the authorization code. Without PKCE it could redeem it. With PKCE it lacks the code_verifier, which never left the real app, so the token endpoint answers invalid_grant.

Mistakes to avoid

  • Using code_challenge_method=plain, which sends the secret itself.
  • Thinking PKCE replaces state: state protects against CSRF on the callback, PKCE against code injection and theft.

They may also ask you

  • Why is the implicit flow deprecated?
  • How would you secure tokens in a single-page app?