Skip to content

Menu

OAuth 2.0 and OIDC Cheat Sheet: Flows, PKCE and Tokens

Checked against OAuth 2.0 / OpenID Connect RFC 6749, 7636, 8628, 9700; OAuth 2.1 draft 17; OIDC Core 1.0 errata 2 on 28 November 2026. Each section links to the official docs it was checked against.

This sheet is for developers wiring an app to an identity provider who need to know which flow to use and which parameters go where. It follows RFC 6749, PKCE (RFC 7636), the device grant (RFC 8628), the January 2025 security BCP (RFC 9700), OAuth 2.1 draft 17 and OpenID Connect Core 1.0. Request and response rows come from the specs; only the PKCE calculation was run locally.

Authorization code with PKCEThe client keeps the verifier and sends only its S256 hash on the authorization request; the token request then proves the same client started the flow.ClientAuth serverClient makes a fresh code_verifier per login andkeeps itGET /authorizecode_challenge (S256), state,scopeOne-time codestate ties it to this sessionPOST /tokencode, redirect_uri, code_verifieraccess_token, token_typeCode reused or expired, or verifier doesn't match→ invalid_grant
The client keeps the verifier and sends only its S256 hash on the authorization request; the token request then proves the same client started the flow.

When to use what

If a user signs in through a browser, use the authorization code flow with PKCE. That holds for single-page apps, mobile apps and server-rendered apps alike: RFC 9700 makes PKCE mandatory for public clients and recommends it for confidential ones, and the OAuth 2.1 draft keeps only this flow for user sign-in.

If no user is involved, such as a cron job calling an API, use client credentials. If the device has no browser or a poor keyboard, like a TV or a CLI tool, use the device authorization grant. Refresh tokens are not a flow of their own; they let any of these keep going without asking the user again.

Add OpenID Connect when you need to know who the user is, not just to call an API on their behalf. You ask for the openid scope and receive an ID token for your app to read; the access token is for the API and your app should treat it as opaque. Our OAuth 2.0 implementation guide covers the server side, the OAuth mistakes post lists what goes wrong in practice, and remote MCP server authorization shows the same flow inside MCP.

The verifier is 43 to 128 characters from A-Z a-z 0-9 - . _ ~. The challenge is BASE64URL(SHA256(verifier)) without padding. The plain method exists but should not be used in new code.

code_verifier=<43-128 random chars>

Generate a fresh secret per login and keep it in the client

code_challenge=<base64url sha256 of verifier>&code_challenge_method=S256

Send the hashed verifier on the authorization request

GET /authorize?response_type=code&client_id=...&redirect_uri=...&scope=...&state=...

Start the login in the browser; state ties the response to this session

From the docs, not run by us
POST /token grant_type=authorization_code&code=...&redirect_uri=...&code_verifier=...

Swap the one-time code for tokens and prove you started the flow

From the docs, not run by us
error=invalid_grant

Token endpoint reply when the code is reused, expired or the verifier doesn't match

From the docs, not run by us

Client credentials and refresh are in RFC 6749 sections 4.4 and 6 (https://www.rfc-editor.org/rfc/rfc6749).

POST /token grant_type=client_credentials&scope=...

Get a token for a service with no user involved

From the docs, not run by us
POST /device_authorization client_id=...&scope=...

Start a device login; returns device_code, user_code, verification_uri, expires_in and an optional interval

From the docs, not run by us
grant_type=urn:ietf:params:oauth:grant-type:device_code

Poll the token endpoint with this grant and the device_code

From the docs, not run by us
authorization_pending / slow_down

Keep polling; on slow_down add 5 seconds to the interval for all later polls

From the docs, not run by us
access_denied / expired_token

Stop polling: the user said no or the device code ran out

From the docs, not run by us
POST /token grant_type=refresh_token&refresh_token=...

Get a new access token; the scope may only narrow, never widen

From the docs, not run by us

Revocation is RFC 7009 (https://www.rfc-editor.org/rfc/rfc7009). It returns 200 even for an unknown token, so you can't use it to test whether a token exists.

access_token, token_type, expires_in, refresh_token, scope

Fields in a token response; only the first two are always required

Try it: oauth-token-debuggerFrom the docs, not run by us
POST /introspect token=...&token_type_hint=access_token

Ask the server whether an opaque token is live; the caller must authenticate

Try it: oauth-token-debuggerFrom the docs, not run by us
{"active": false}

Introspection answer for an expired, revoked or unknown token, with no other fields

From the docs, not run by us
POST /revoke token=...&token_type_hint=refresh_token

Revoke a token at logout

From the docs, not run by us

OIDC Core lists 13 ID token validation steps in section 3.1.3.7; the rows below are the ones people skip.

scope=openid profile email

The openid scope turns an OAuth request into an OIDC sign-in

From the docs, not run by us
iss, sub, aud, exp, iat

Claims every ID token must carry; aud must contain your client_id

Try it: JWT DecoderFrom the docs, not run by us
nonce

Random value you send and must find unchanged in the ID token

From the docs, not run by us
auth_time

When the user last actively logged in; present if you asked with max_age

From the docs, not run by us
GET /userinfo with Authorization: Bearer <access_token>

Fetch profile claims; its sub must match the ID token's sub

From the docs, not run by us
response_type=token

Implicit grant: tokens in the URL fragment; replaced by code plus PKCE

From the docs, not run by us
grant_type=password

Resource owner password grant: the app sees the user's password; RFC 9700 says it must not be used

From the docs, not run by us
code_challenge_method=plain

Plain PKCE is explicitly forbidden in OAuth 2.1; S256 is the method to use

From the docs, not run by us
redirect_uri wildcard matching

Servers must compare redirect URIs as exact strings; only loopback redirect URIs of native apps may vary the port

From the docs, not run by us
GET /api?access_token=...

Access token in the URL query: OAuth 2.1 says clients must not send it and resource servers must ignore it

From the docs, not run by us

Worked example: Compute a PKCE challenge and check it against the RFC

PKCE bugs are usually encoding bugs: standard base64 instead of base64url, or padding left on. RFC 7636 Appendix B gives a test vector, so we ran it.

import base64, hashlib
verifier = "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk"
digest = hashlib.sha256(verifier.encode()).digest()
print(base64.urlsafe_b64encode(digest).rstrip(b"=").decode())
# E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM

The printed value matches the challenge in the RFC exactly, so this three-line function is safe to use in a client. Send it as code_challenge with code_challenge_method=S256 on the authorization request and keep the verifier in memory or session storage. When you exchange the code, send the original verifier. The server hashes it the same way; if the result doesn't match the stored challenge it answers invalid_grant. An attacker who steals the code from a redirect can't use it, because the verifier never travelled through the browser. Our PKCE generator produces a matching pair if you want to test against a dev server by hand.

Common mistakes

  • Skipping state or nonce because PKCE is in place

    RFC 9700 accepts PKCE as CSRF protection only if the server enforces it. Keep state for your own session binding and nonce for OIDC.

  • Using the ID token as a bearer token for your API

    The ID token's audience is your client, not the API. Send the access token to APIs and read the ID token only in the client.

  • Registering wildcard or prefix redirect URIs

    Register each full redirect URI. Servers following RFC 9700 compare them as exact strings.

  • Keeping long-lived refresh tokens in a browser app without rotation

    Turn on refresh token rotation at the provider so a stolen refresh token stops working after the next use.

  • Confusing scopes with claims

    Scopes are what the client asks permission for; claims are facts about the user inside a token. Check claims, not requested scopes, when authorizing.