admin_hub

sysop@hub:~/explainers/oauth-flow-explained$

oauth-flow-explained

OAuth 2.0 authorization code flow with PKCE

How an app signs a user in and gets tokens from Microsoft Entra ID, step by step.

Read the steps as text
  1. Click Sign in. The user starts sign-in in the app.
  2. Authorization request. The app redirects the browser to the authorization endpoint with client_id, redirect_uri, scope, a random state value and a PKCE code_challenge.
  3. Sign-in, MFA, consent. Entra ID authenticates the user, applies Conditional Access and MFA, and asks for consent to the requested permissions if needed.
  4. Redirect with code. Entra ID sends the browser back to the redirect_uri with a short-lived authorization code and the state value. The app checks that state matches. The code alone is useless without the PKCE code_verifier.
  5. Token request. The app sends the code and the PKCE code_verifier to the token endpoint. Confidential clients also prove themselves with a secret or certificate.
  6. Tokens. Entra ID returns an access token, an ID token when the openid scope was requested, and a refresh token when offline_access was requested.
  7. Call API with token. The app calls the API with the access token in the Authorization: Bearer header.
  8. Response. The API validates signature, issuer, audience, expiry and scopes before it answers.

Good to know

  • The state value protects against cross-site request forgery. PKCE protects against a stolen authorization code and is recommended for all clients.
  • Access tokens are short-lived, usually around an hour. A refresh token gets new ones without another sign-in.
  • Errors in this flow show up as AADSTS codes, for example 65001 for missing consent at the sign-in step or 50011 for a redirect URI mismatch.

Related: AADSTS65001AADSTS50011JWT decoder