29 November 2026 · 14 min read · Download as PDF
OAuth 2.0 vs OpenID Connect: the authorization code flow with PKCE, request by request
OAuth 2.0 decides what an app may do with an API; OpenID Connect adds who signed in. The authorization code flow with PKCE as real HTTP requests, every token field and the spec behind it, a side-by-side table, the edge cases, and where OAuth 2.1 stands.
OAuth 2.0 decides what an app may do with an API on your behalf. OpenID Connect (OIDC) is a thin layer on top of it that tells the app who you are. Most apps use both in one round trip: the authorization code flow with PKCE (Proof Key for Code Exchange), plus the openid scope.
The video lessons in OAuth 2.0 and OpenID Connect, Drawn Out walk that flow and the sign-in step by step on diagrams. This article is the reference to keep beside them: the exact HTTP requests and token fields, the spec clause behind each rule, a side-by-side table, the edge cases that catch people out, and an FAQ.
TL;DR
- OAuth 2.0 is authorization. It issues an access token addressed to an API. It's defined in RFC 6749, an Internet Engineering Task Force (IETF) Request for Comments from October 2012.
- OpenID Connect is authentication on top of OAuth 2.0. Add
scope=openidand the token response also carries an ID token: a signed JSON Web Token (JWT) addressed to your app, saying who signed in, when and at which provider. - In practice it's one flow, not two. OpenID Connect reuses OAuth's endpoints and the authorization code grant (it also defines implicit and hybrid flows, which new apps rarely need). It adds the
openidscope, the ID token, anonce(optional in the code flow, required in implicit), a UserInfo endpoint and discovery. - Use the authorization code flow with PKCE for every app with a user. RFC 9700, the OAuth 2.0 Security Best Current Practice (January 2025), says public clients MUST use PKCE and recommends it for confidential clients too. Implicit SHOULD NOT be used; the password grant MUST NOT be.
- Key your users by
iss+sub, never by email. OpenID Connect Core says they're "the only Claims that an RP can rely upon as a stable identifier". - OAuth 2.1 isn't out yet. On 28 Nov 2026 it is draft 17 (31 Oct 2026), with the working group aiming to send it to the Internet Engineering Steering Group (IESG) in December 2026. Most of its security rules are already in RFC 9700, so you can follow those today.
OAuth 2.0 vs OpenID Connect, side by side
OAuth 2.0 | OpenID Connect | |
|---|---|---|
Question it answers | What may this app do with this API? | Who just signed in to this app? |
Spec | RFC 6749 (2012), with RFC 6750 for bearer tokens, RFC 7636 for PKCE and RFC 9700 for current security practice | OpenID Connect Core 1.0, Final, incorporating errata set 2 (15 Dec 2023), from the OpenID Foundation |
Parties | Resource owner, client, authorization server, resource server (the API) | End-user, relying party (the client), OpenID provider (the authorization server) |
How a request says which | Any scopes the API defines |
|
Main token | Access token | ID token, alongside the access token |
Token addressed to | The API it's meant for (RFC 9700: access tokens SHOULD be audience-restricted) | The app: its |
Token format | Not defined; often opaque, or a JWT under RFC 9068 | Always a JWT, and signed (unsigned only in the code flow, and only if the app registered for it) |
Who reads the token | The API. The app should pass it on without reading it | The app, once, at sign-in |
Replay protection |
| Adds |
Endpoints | Authorization and token endpoints, at whatever URLs the server publishes (RFC 8414 metadata); | UserInfo, and |
Stable user identifier | None defined |
|
Use it for | Calling APIs; service to service with client credentials | Signing people in, single sign-on |
The authorization code flow with PKCE, as HTTP
Here is the whole exchange on the wire, with the OpenID Connect additions marked. The host names, endpoint paths and values are made up (read the real endpoints from the provider's metadata), and headers are trimmed to the ones that matter, apart from the PKCE pair, which is RFC 7636's own worked example (Appendix B), so you can check your code against it.

The authorization code flow with PKCE: front channel in blue, back channel in purple. Open this diagram in archhy to copy it and change it for your own system.
1. Make the verifier and the challenge
The verifier is 43 to 128 characters from A-Z a-z 0-9 - . _ ~. RFC 7636 recommends 32 random bytes, base64url-encoded, which gives exactly 43 characters. The challenge is the base64url-encoded SHA-256 of the verifier, with no padding:
# a fresh verifier: 32 random bytes, base64url, no paddingopenssl rand 32 | openssl base64 | tr '+/' '-_' | tr -d '=\n'# the S256 challenge for RFC 7636's example verifierprintf %s 'dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk' \ | openssl dgst -sha256 -binary | openssl base64 | tr '+/' '-_' | tr -d '=\n'# E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cMKeep the verifier in the app (in the server session, or in memory in a single-page or mobile app). It never goes through the browser's address bar.
2. The authorization request (front channel)
GET /authorize?response_type=code &client_id=s6BhdRkqt3 &redirect_uri=https%3A%2F%2Fapp.example.com%2Fcallback &scope=openid%20profile%20orders.read # openid makes it OpenID Connect &state=af0ifjsldkj &nonce=n-0S6_WzA2Mj # OpenID Connect only &code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM &code_challenge_method=S256 HTTP/1.1Host: login.example.comLine breaks and comments are for reading only. Two details matter. code_challenge_method defaults to plain if you leave it out, so send S256 explicitly. And the redirect_uri must match a registered one exactly: RFC 9700 requires exact string matching, with one exception: a native app's loopback redirect (localhost) may use any port, as RFC 8252 describes.
3. The authorization response (front channel)
HTTP/1.1 302 FoundLocation: https://app.example.com/callback?code=SplxlOBeZQQYbYS6WxSbIA &state=af0ifjsldkj &iss=https%3A%2F%2Flogin.example.com # if the server supports RFC 9207The app checks that state is the value it sent; state must be random, used once and tied to this browser session, never a fixed value like the one above. If iss is present, the app must check it equals the issuer it sent the request to (RFC 9207 §2.4). The code is single use and short-lived: RFC 6749 recommends a lifetime of at most 10 minutes.
4. The token request (back channel)
POST /token HTTP/1.1Host: login.example.comContent-Type: application/x-www-form-urlencodedgrant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA&redirect_uri=https%3A%2F%2Fapp.example.com%2Fcallback&client_id=s6BhdRkqt3&code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXkA confidential client (one with a server that can keep a secret) also authenticates here, for example with HTTP Basic, private_key_jwt or mutual Transport Layer Security (mTLS). RFC 9700 recommends the asymmetric options. A public client, such as a single-page or mobile app, sends only its client_id; the code_verifier is what proves it's the app that started the flow.
5. The token response
HTTP/1.1 200 OKContent-Type: application/jsonCache-Control: no-storePragma: no-cache{ "access_token": "SlAV32hkKG", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "8xLOxBtZp8", "scope": "openid profile orders.read", "id_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjFlOWdkazcifQ.ewogImlzc..."}Field | Required? | Source |
|---|---|---|
| Required | RFC 6749 §5.1 |
| Required; | RFC 6749 §5.1, OIDC Core §3.1.3.3 |
| Recommended, in seconds | RFC 6749 §5.1 |
| Optional | RFC 6749 §5.1 |
| Optional if it's what you asked for; required if it differs | RFC 6749 §5.1 |
| Required in an OpenID Connect response | OIDC Core §3.1.3.3 |
Check the granted scope: the server can grant less than you asked for.
6. Calling the API
GET /orders HTTP/1.1Host: api.example.comAuthorization: Bearer SlAV32hkKGSend the access token in the Authorization header (RFC 6750), never in the URL: the OAuth 2.1 draft drops query-string bearer tokens altogether.
What each parameter protects against
Value | Made by | Travels | Stops | Rule |
|---|---|---|---|---|
| App, per request | Out and back through the browser | A forged callback (cross-site request forgery, CSRF); also carries the app's own context | RFC 6749 §4.1.1, RFC 9700 §2.1 |
| App, per request | Challenge out through the browser; verifier only to | A stolen or injected code being redeemed by someone else | RFC 7636; RFC 9700 §2.1.1 |
| App, per request | Out through the browser; back inside the signed ID token | An old ID token replayed into a new sign-in | OIDC Core §2, §3.1.3.7 |
| Authorization server | Back through the browser | Mix-up attacks when an app uses several servers | RFC 9207, RFC 9700 §2.1 |
Exact | Registered in advance | Checked by the server | Codes and tokens sent to an attacker's address | RFC 9700 §2.1 |
Inside the tokens
The ID token's claims
Decode the middle part of an ID token and you get a JSON object like this one, the example in OpenID Connect Core §2:
{ "iss": "https://server.example.com", "sub": "24400320", "aud": "s6BhdRkqt3", "nonce": "n-0S6_WzA2Mj", "exp": 1311281970, "iat": 1311280970, "auth_time": 1311280969, "acr": "urn:mace:incommon:iap:silver"}Claim | Required? | What it is | What to check |
|---|---|---|---|
| Yes | The issuer: a case-sensitive https URL, no query or fragment | Matches the issuer you discovered, character for character |
| Yes | The user at that issuer: never reassigned, at most 255 ASCII characters, case-sensitive | Store it with |
| Yes | Who the token is for; a string or an array | Contains your |
| Yes | Expiry, in seconds since 1970 (UTC) | Now is before it, allowing a few minutes of clock skew at most |
| Yes | When it was issued | Not too far from now; limits how long you keep nonces |
| If you sent one | Your value, passed through unchanged | Equals what you sent |
| If you sent | When the user actually authenticated | Recent enough for what they're doing |
| Optional | How strongly, and by which methods, the user authenticated | If you asked for a level, that you got it |
| Optional (code flow) | Half of a hash of the access token | Ties the access token to this ID token if present |
| Optional | The party the token was issued to | Only with extensions that use it; otherwise ignore it |
Any claim you don't understand must be ignored, not rejected.

Two tokens, two audiences: the ID token stays with the app, the access token goes to the API. Open this diagram in archhy.
The access token
OAuth 2.0 doesn't define what an access token looks like. Many providers issue opaque strings that the API checks by asking the provider (token introspection, RFC 7662). Others issue JWTs under RFC 9068, which marks them with the header "typ": "at+jwt"; an API using that profile must reject any other typ, which stops an ID token being accepted as an access token. Either way the API checks the signature (for a JWT) or the introspection result, that it is an intended audience of the token, the expiry, and the scopes for the action asked for. RFC 9700 says tokens SHOULD be audience-restricted and an API MUST refuse one not meant for it.
Validating an ID token, in order
OpenID Connect Core §3.1.3.7 lists the checks. In practice, for the authorization code flow:
- If it's encrypted, decrypt it with the keys you registered.
issexactly equals the issuer from discovery.audcontains yourclient_id; reject it if it lists audiences you don't trust.- Verify the signature with a key from the provider's JSON Web Key Set (JWKS), checking the algorithm is one you expect (RS256 by default). An unsigned token (
alg: none) is allowed only in the code flow, and only if you registered for it; otherwise reject it. - Now is before
exp;iatis reasonable. nonceequals the one you sent.- If you asked for
acrormax_age, checkacrandauth_time.
Then create your own session and stop using the ID token. Its exp is "unrelated" to how long your session lasts, says the spec.

The same flow with the OpenID Connect parts added: scope=openid, a nonce, an ID token, and UserInfo. Open this diagram in archhy.
Edge cases that catch people out
- "We have a client secret, so we don't need PKCE." RFC 9700 recommends PKCE for confidential clients too: it blocks authorization code injection, which client authentication doesn't, because the attacker redeems the stolen code through your real client. Confidential OpenID Connect clients may use the
nonceinstead, with extra precautions. statewith PKCE. RFC 9700 lets a client rely on PKCE for CSRF protection once it has made sure the server supports PKCE, and says thenoncedoes that job in OpenID Connect. Most libraries still sendstate, and you need it anyway to carry where the user was going.- The
plainmethod. It sends the verifier itself in the browser. RFC 7636 allows it only when S256 is impossible; RFC 9700 says S256 is currently the only method that doesn't expose the verifier; the OAuth 2.1 draft removesplain. - PKCE downgrade. A server must reject a token request with a
code_verifierif the authorization request had nocode_challenge. Check that your provider advertisescode_challenge_methods_supportedin its metadata. - A code used twice. The server must refuse the second use and should revoke the tokens issued from the first. A callback that retries the token request can end up holding revoked tokens.
- Several identity providers. With "Sign in with A or B", defend against mix-up attacks: check the
issresponse parameter (RFC 9207), or the ID token'siss, or use a different redirect address per provider. - The signature check you're allowed to skip. When the ID token comes straight from the token endpoint over TLS, the spec lets you rely on TLS to vouch for the issuer instead of checking the signature. Libraries check it anyway, and you should too if the token is ever passed on.
audas an array. It's valid. Find yourclient_idin it rather than comparing strings.- Email as the user key. Emails change and get reused.
iss+subis the only guaranteed stable key, andsubis only unique within its issuer. - Refresh tokens in a single-page or mobile app. RFC 9700 says a public client's refresh tokens must be sender-constrained or rotated on each use; RFC 10017 (browser-based apps, August 2026) adds lifetime limits for browsers, and strongly recommends a Backend for Frontend (BFF), a server component that keeps the tokens out of the browser, for business and sensitive apps and any that handle personal data.
- Stolen access tokens. A bearer token works for whoever holds it. RFC 9700 recommends sender-constrained tokens with mutual TLS (RFC 8705) or DPoP, Demonstrating Proof of Possession (RFC 9449).
- Old grants. Implicit (
response_type=token) SHOULD NOT be used unless token leakage and injection are mitigated, which is hard in practice; the resource owner password grant MUST NOT be. OpenID Connect's own implicit and hybrid flows still exist in the spec, but new apps should usecode.
Where the specs stand on 28 Nov 2026
Document | Date | Status |
|---|---|---|
RFC 6749, OAuth 2.0 | Oct 2012 | Standards Track; still the base |
RFC 6750, Bearer Token Usage | Oct 2012 | Standards Track |
RFC 7636, PKCE | Sep 2015 | Standards Track |
OpenID Connect Core 1.0, errata set 2 | 15 Dec 2023 | Final (OpenID Foundation) |
RFC 9700, OAuth 2.0 Security Best Current Practice (BCP 240) | Jan 2025 | Best Current Practice |
RFC 10017, OAuth 2.0 for Browser-Based Applications | Aug 2026 | Best Current Practice |
OAuth 2.1, draft-ietf-oauth-v2-1-17 | 31 Oct 2026 | Internet-Draft, working group document; not yet an RFC |
OAuth 2.1 folds OAuth 2.0, PKCE, bearer tokens, native and browser apps and RFC 9700 into one document. Its own list of changes: PKCE by default for the authorization code grant, exact redirect matching, no implicit or password grants, no bearer tokens in query strings, sender-constrained or one-time refresh tokens for public clients, no redirect_uri in the token request, and no plain PKCE. It doesn't remove OpenID Connect's response_type=id_token. If you already follow RFC 9700 you're most of the way there, but not all the way: dropping redirect_uri from the token request and removing plain PKCE are new in the draft, and a server that supports both versions must still accept redirect_uri from OAuth 2.0 clients.
FAQ
Is OpenID Connect a replacement for OAuth 2.0?
No. It's built on OAuth 2.0 and uses the same endpoints and flows. An OpenID Connect provider is an OAuth 2.0 authorization server that also issues ID tokens.
Can I sign users in with plain OAuth 2.0?
Not safely. An access token says an app may call an API, not who is at the keyboard, and it may have been issued to a different app. That gap is what the ID token closes: its aud names your app and its nonce ties it to this sign-in.
Does OpenID Connect require PKCE?
OpenID Connect Core 1.0 doesn't mention it, because PKCE came later. RFC 9700 makes it mandatory for public clients and recommended for all others, so use it with OpenID Connect too.
Should I send the ID token to my API?
No. Its audience is your app, not the API. Send the access token. If your API is your own back end serving the same app, use your session cookie.
Is the client_id a secret?
No. It's in every authorization URL. Only a confidential client's credentials (a secret, a private key or a certificate) are secret.
Is OAuth 2.1 a standard yet?
Not on 28 Nov 2026. It's an Internet-Draft (version 17, 31 Oct 2026), and the working group's milestone is to send it to the IESG, in December 2026. Most of its security rules are already best practice through RFC 9700; a few, like dropping redirect_uri from the token request, are new.
Where does SAML fit?
SAML 2.0, the Security Assertion Markup Language, does single sign-on with XML assertions and is common in older enterprise apps. New integrations usually choose OpenID Connect; lesson 6 compares the three.
Keep going
- Watch the flow drawn out: The authorization code flow with PKCE, step by step, then OpenID Connect sign-in and the ID token and ID token or access token, signing out, and OIDC vs SAML, short free lessons with Space Llama.
- Read archhy's longer guides, which the diagrams come from: How OAuth 2.0 works: every flow, drawn out and OpenID Connect explained.