Skip to content

Search

Articles, tools, solutions and knowledge base guides

Start typing to search across articles, tools and apps.

OAuth 2.1, OpenID Connect and PKCE: what should actually be used for login

OAuth, OpenID Connect and PKCE are often discussed as if they were one mechanism, but they solve different problems. OAuth delegates access to resources, OpenID Connect adds an authentication layer, and PKCE protects the Authorization Code Flow against code interception. A secure login architecture therefore starts by separating authentication, authorization and the application's own session.

Published Written by Reading time 24 min read
On this page Contents: quick navigation between sections

OAuth 2.0, OAuth 2.1 and OpenID Connect are not the same

MechanismPurposeMain artifact
OAuth 2.0 / 2.1Delegated authorizationAccess token
OpenID ConnectUser authenticationID Token
PKCEProtect Authorization Code Flowcode_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 typeRecommended patternWhere tokens live
SPA, lower riskAuthorization Code + PKCEBrowser
SPA, sensitive dataBFF + Authorization Code + PKCEBackend
Mobile appExternal browser + Authorization Code + PKCESecure app storage
Traditional server appConfidential client + Authorization CodeServer

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 and nonce in ID Tokens.
  • Use exact registered redirect URIs.
  • Design refresh-token rotation, revocation and expiry.

The main rule is simple: OAuth should not be used by itself as a user-login protocol. If an application needs to know who signed in, it should use OpenID Connect. Authorization Code Flow with PKCE is the core secure pattern for public clients today, while browser applications handling sensitive data should consider a BFF. OAuth 2.1 consolidates these practices but is still a draft at publication time, so production decisions should rely on the published RFCs and BCPs it draws from.

OAuth 2.1 OAuth 2.0 OpenID Connect PKCE Authentication Authorization Security SPA BFF Mobile Authentication Access Token ID Token

Frequently asked questions

Is OAuth 2.1 already an RFC?

No. At publication time, the current document is active Internet-Draft draft-ietf-oauth-v2-1-17. [1]

Is OAuth a login protocol?

OAuth itself is for authorization. User login should use OpenID Connect, which adds an identity layer and ID Token. [3][8]

Is PKCE only for mobile apps?

No. RFC 9700 states that PKCE guidance applies to all kinds of OAuth clients, including web applications. [2]

Can code_challenge_method=plain still be used?

For modern deployments use S256. The current OAuth 2.1 draft removes plain. [1][2]

Can an SPA have a client secret?

An SPA is a public client and cannot effectively keep a static embedded secret confidential. [5]

Can an ID Token be sent to an API as a bearer token?

It should not replace an access token. ID Tokens are for the client; access tokens are for resource servers. [3][9]

Are state and nonce the same?

No. state is an OAuth parameter carrying request state; nonce is an OIDC value linking the client session to the ID Token. [3][8]

Is Implicit Flow still recommended for SPAs?

No. RFC 10017 recommends Authorization Code Flow with PKCE for browser-based applications. [5]

Should a mobile app use an embedded WebView for OAuth?

No. RFC 8252 recommends an external user-agent, normally the system browser. [6]

What is DPoP for?

DPoP binds a token to a client key, reducing the value of a stolen token to another party. [10]

How can a resource server check an opaque token?

It can use OAuth token introspection under RFC 7662 when the authorization server supports it. [12]

Can a refresh token be revoked?

Yes. RFC 7009 defines OAuth token revocation. [11]

Sources and references

  1. IETF, The OAuth 2.1 Authorization Framework, draft-ietf-oauth-v2-1-17↩1↩2↩3↩4↩5↩6↩7
  2. RFC 9700, Best Current Practice for OAuth 2.0 Security↩1↩2↩3↩4↩5↩6↩7↩8↩9↩10↩11
  3. OpenID Foundation, OpenID Connect Core 1.0 incorporating errata set 2↩1↩2↩3↩4↩5↩6↩7↩8↩9↩10
  4. RFC 7636, Proof Key for Code Exchange by OAuth Public Clients↩1↩2↩3↩4↩5↩6↩7
  5. RFC 10017, OAuth 2.0 for Browser-Based Applications↩1↩2↩3↩4↩5↩6↩7↩8
  6. RFC 8252, OAuth 2.0 for Native Apps↩1↩2↩3↩4↩5↩6
  7. RFC 8414, OAuth 2.0 Authorization Server Metadata↩
  8. RFC 6749, The OAuth 2.0 Authorization Framework↩1↩2↩3↩4↩5↩6
  9. RFC 6750, OAuth 2.0 Bearer Token Usage↩1↩2↩3
  10. RFC 9449, OAuth 2.0 Demonstrating Proof of Possession (DPoP)↩1↩2
  11. RFC 7009, OAuth 2.0 Token Revocation↩1↩2
  12. RFC 7662, OAuth 2.0 Token Introspection↩1↩2

Was this helpful?

Get new articles by email

One short email per new Learning article. No spam, unsubscribe in one click.

We only use your email to send new articles. No third-party sharing.

Back to Learning