OAuth 2.0, OAuth 2.1 and OpenID Connect are not the same
| Mechanism | Purpose | Main artifact |
|---|---|---|
| OAuth 2.0 / 2.1 | Delegated authorization | Access token |
| OpenID Connect | User authentication | ID Token |
| PKCE | Protect Authorization Code Flow | code_verifier + code_challenge |
OAuth 2.0 defines an authorization framework for obtaining limited access to protected resources. It does not by itself define user authentication. [8]
OpenID Connect is an identity layer on top of OAuth 2.0. It adds the openid scope and ID Token so the client can receive an authentication result. [3]
OAuth 2.1 is currently the active Internet-Draft draft-ietf-oauth-v2-1-17, not an RFC. It consolidates current security guidance and removes older mechanisms. [1]
What OAuth 2.1 changes
The current OAuth 2.1 draft requires PKCE for Authorization Code Flow, removes the Implicit and Resource Owner Password Credentials grants, requires exact redirect URI matching and removes the PKCE plain method. [1]
These changes align with later security guidance, especially RFC 9700, which deprecates Implicit and ROPC and strengthens PKCE requirements. [2]
Product documentation should not claim that OAuth 2.1 is already an RFC standard while it remains an Internet-Draft.
OAuth is authorization, OIDC is login
An access token tells a resource server that a client has permission to access a resource. It is not a universal user-identity proof for the client application. [8][9]
OpenID Connect adds an ID Token with claims such as iss, sub, aud, iat and, depending on the flow, nonce. [3]
For a 'Sign in with...' feature, use OIDC instead of trying to infer identity from an arbitrary access token.
Authorization Code Flow with PKCE
PKCE makes an intercepted authorization code useless without an additional secret generated by the client, the code_verifier. [4]
The client creates a verifier, derives a code_challenge, sends the challenge in the authorization request and later sends the original verifier to the token endpoint. [4]
RFC 9700 recommends S256, and authorization servers must support and enforce PKCE correctly. [2]
Example authorization request with PKCE and OIDC
Example of the complete request structure, shown on one line
GET /authorize?response_type=code&client_id=web_app&redirect_uri=https%3A%2F%2Fapp.example.com%2Fcallback&scope=openid%20profile%20email&state=af0ifjsldkj&nonce=n-0S6_WzA2Mj&code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM&code_challenge_method=S256
A modern login request normally includes response_type=code, scope=openid, state, nonce, code_challenge and code_challenge_method=S256. OIDC requires the openid scope for an authentication request. [3][4]
The state, nonce and authorization-code values are illustrative. The code_challenge below is the real S256 result for the code_verifier shown later. In a real application, state, nonce, challenge and verifier must be generated for the individual transaction rather than copied as constants. [2][3][4]
Example code-to-token exchange
Example token-request structure
POST /token
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&
code=SplxlOBeZQQYbYS6WxSbIA&
redirect_uri=https%3A%2F%2Fapp.example.com%2Fcallback&
client_id=web_app&
code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk
After the callback, the client sends the authorization code to the token endpoint together with the code_verifier. A public client should not pretend that a client secret embedded in the app is confidential. [4][6]
The redirect_uri is repeated exactly as in the authorization request. The shown code_verifier matches the earlier code_challenge. The authorization code itself is illustrative and in a real flow comes from the authorization-server callback. [4][8]
ID Token and access token have different jobs
The ID Token is for the client as the authentication result. The client must validate its signature and required claims, including issuer and audience. [3]
The access token is for the resource server and authorizes API requests. RFC 6750 describes bearer-token use in the Authorization header. [9]
Do not use an ID Token as a replacement for an API access token when the API expects an access token.
Example: SPA without a backend
RFC 10017 says browser-based applications acting as public clients should use Authorization Code Flow with PKCE. [5]
A SPA cannot safely hide a static client secret because code and data running in the browser are accessible to the user and potentially to injected scripts.
In this architecture the access token reaches browser code, so XSS defenses and short token lifetimes matter greatly. [5]
Example: BFF for a business application
RFC 10017 defines the Backend for Frontend pattern where the backend becomes the confidential OAuth client, stores access and refresh tokens server-side and exposes its own cookie-based session to the browser. [5]
The browser does not need to receive the access token in JavaScript. The BFF forwards API requests with the correct token. [5]
The RFC presents BFF as the strongest of its browser patterns and strongly recommends it for business, sensitive and personal-data applications. [5]
Example: mobile application
RFC 8252 recommends that native applications perform OAuth through an external user-agent, typically the system browser, rather than an embedded WebView controlled by the app. [6]
Public native clients must use PKCE because they cannot safely rely on an embedded client secret. [6]
Redirect handling can use platform-specific mechanisms, but the authorization server should enforce the native-app BCP requirements.
Redirect URIs need strict handling
OAuth Security BCP requires exact redirect URI matching, apart from special loopback rules for native applications. [2][6]
Loose prefix matching or broad wildcards can let an attacker capture authorization responses at an unintended endpoint.
OAuth 2.1 carries exact redirect URI matching forward as a core security requirement. [1]
state and nonce solve different problems
state and nonce are not the same mechanism. nonce belongs to OpenID Connect and, when sent, the client must validate the corresponding claim in the ID Token. [3]
RFC 9700 clarifies CSRF protection: a client that has ensured the authorization server supports PKCE may rely on PKCE for CSRF protection. In OpenID Connect flows, nonce can also provide that protection. If the client relies on neither PKCE nor nonce, it should use a one-time CSRF token in state securely bound to the user-agent session. [2]
state can still carry application state, for example a safe post-login return location. If integrity matters, its contents must be protected against tampering or swapping between sessions. [2][8]
Refresh tokens need their own security policy
RFC 9700 requires refresh tokens issued to public clients to be sender-constrained or rotated on every use in a way that can detect replay. [2]
The OAuth 2.1 draft adopts this requirement for public clients. [1]
DPoP can sender-constrain access tokens and, for public clients, refresh tokens by binding them to a client-held key. [10]
Metadata, revocation and introspection
RFC 8414 defines authorization-server metadata so clients can discover endpoints, issuer and supported mechanisms. [7]
RFC 7009 defines token revocation so a client can tell the authorization server that a token should no longer be used. [11]
RFC 7662 defines token introspection so a resource server can query token activity and metadata. [12]
What to choose in practice
| Application type | Recommended pattern | Where tokens live |
|---|---|---|
| SPA, lower risk | Authorization Code + PKCE | Browser |
| SPA, sensitive data | BFF + Authorization Code + PKCE | Backend |
| Mobile app | External browser + Authorization Code + PKCE | Secure app storage |
| Traditional server app | Confidential client + Authorization Code | Server |
For user login, use OpenID Connect on Authorization Code Flow with PKCE. For delegated API access, use OAuth access tokens; for the client's authentication result, validate the ID Token according to OIDC. [2][3][4]
For SPAs handling sensitive data, consider a BFF. For mobile apps, use the external browser plus PKCE. [5][6]
Do not start a new design on Implicit Grant or Resource Owner Password Credentials Grant. Modern security guidance rejects both, and OAuth 2.1 omits them. [1][2]
- User login: OIDC + Authorization Code + PKCE.
- Delegated API access: OAuth access token.
- Sensitive SPA: prefer BFF.
- Mobile app: external browser + PKCE.
- Do not put a supposedly secret client secret in SPA or mobile code.
- Validate
iss,aud, signature andnoncein ID Tokens. - Use exact registered redirect URIs.
- Design refresh-token rotation, revocation and expiry.
