By NHI Mgmt Group Editorial TeamBased on WorkOS: “OAuth 2.0 Authorization Code Grant: What it is & how it works” (July 16, 2025)

TL;DR: OAuth 2.0 authorization code flow uses a browser-based consent step, a short-lived authorization code, and a backend token exchange, while OAuth 2.1 makes PKCE mandatory to block interception attacks, according to WorkOS. The security model is only as strong as redirect validation, state checking, and secret handling, not the protocol label.


At a glance

What this is: This is a guide to OAuth authorization code flow and PKCE, showing how browser consent, redirect handling, and backend token exchange work together to secure delegated access.

Why it matters: It matters because identity teams that rely on OAuth need to validate redirect URIs, state, and token exchange handling to prevent code interception and keep delegated access trustworthy.


Context

OAuth authorization code flow is the delegated access pattern that exchanges a browser-based consent step for a short-lived code and then a backend token grant. The main governance gap is not the protocol name but whether redirect handling, state validation, and secret storage are implemented correctly across the application.

For IAM teams, the relevant question is how authorization is bounded when the application is not meant to handle user passwords directly. PKCE tightens the handoff between authorization request and token exchange, but it does not remove the need for exact redirect URI matching, CSRF protection, and secure backend credential handling.


Key questions

Q: What breaks when OAuth clients use the wrong flow or skip PKCE?

A: When teams choose the wrong grant type or skip PKCE, the authorization process becomes easier to intercept or misuse. Public clients are harder to protect with a client secret, and authorization codes can be stolen if the flow is not defended properly. The result is weaker assurance that the application receiving tokens is the one that was authorized.

Q: Why do redirect URI checks and state validation both matter in OAuth flows?

A: They protect different parts of the transaction. Exact redirect URI checks make sure the code returns to the intended callback endpoint, while state confirms that the callback belongs to the original request and is not a forged or replayed response. If either control is weak, the flow can be completed in the wrong context.

Q: How should teams implement OAuth authorization code flow in web applications?

A: Use the authorization code grant for browser-based delegated access, keep tokens off the front end, and complete the code exchange from trusted backend code only. Pair that with exact redirect URI matching, state validation, and server-side secret storage so the flow remains bound to the intended application and session.

Q: When should organisations require PKCE in addition to the authorization code grant?

A: They should require PKCE whenever they use OAuth authorization code flow, including confidential clients. OAuth 2.1 treats PKCE as mandatory because code interception remains a realistic threat, and the verifier binding provides an extra control that the basic grant does not supply on its own.


Technical breakdown

Authorization code grant: browser consent to backend token exchange

The authorization code grant separates user consent from token issuance. The app sends the user to the authorization server's /authorize endpoint, receives a temporary code on the redirect URI, and then exchanges that code at /token from the backend. That design keeps access tokens out of the browser and allows the application to authenticate itself with a client secret when appropriate. The security value comes from the sequence, not the label: each step depends on the previous one being validated, especially the redirect URI and state value.

Practical implication: validate the redirect URI exactly and treat the code as a one-time credential that must be exchanged only from trusted backend code.

PKCE and the code verifier binding

PKCE adds a cryptographic binding between the authorization request and the token exchange. The client generates a high-entropy code verifier, derives a code challenge, and sends the challenge during authorization; later it presents the verifier at token exchange, and the server checks that the two match. This prevents an intercepted code from being redeemed by another party, because possession of the code alone is not enough. OAuth 2.1 makes this binding mandatory because interception attacks remain practical wherever codes can be observed or redirected.

Practical implication: require PKCE on every OAuth client, including confidential clients, and keep the verifier available only until the exchange completes.

Redirect validation and state checking as flow integrity controls

Redirect validation and state checking protect the integrity of the authorization flow itself. Exact redirect URI matching prevents attackers from steering codes to an unintended endpoint, while state gives the client a way to verify that the callback corresponds to the original request and not a forged return. These controls do different jobs: redirect matching defends the destination, and state defends the transaction. If either is weak, the flow can be completed against the wrong party even when PKCE is present.

Practical implication: enforce exact redirect URI matching and validate state on every callback before any token exchange logic runs.


NHI Mgmt Group analysis

OAuth authorization code flow is only as strong as the callback integrity controls around it. The flow assumes the browser redirect returns to the exact application endpoint that initiated the request, with the same state value and a valid backend exchange path. When those assumptions fail, the protocol no longer protects delegated access even if the broad OAuth pattern is correct. Practitioners should treat redirect validation and state as governance controls, not implementation details.

PKCE closes the gap between code capture and token redemption, but it does not replace flow validation. The addition of a code verifier makes interception materially harder because possession of the code alone is no longer sufficient. That said, PKCE protects the exchange step, while redirect URI matching and state checking protect the request path. Teams that rely on PKCE alone are reading the control too narrowly.

Authorization code flow is the right default for delegated access because it keeps tokens off the browser path. That architectural separation remains important for web applications that can keep credentials on a backend server. The governance mistake is assuming the flow is secure by default once the app uses /authorize and /token. In practice, the trust boundary moves to the redirect handler, backend secret storage, and callback validation.

OAuth 2.1 is standardising a security expectation that many teams previously treated as optional. Making PKCE mandatory reflects the reality that code interception is not a theoretical edge case. The broader signal for identity teams is that delegated access controls are moving toward stronger request binding, less trust in implicit callback integrity, and tighter treatment of application identity during token exchange.

What this signals

Authorization code flow is a trust-boundary design, not just a login pattern. The important decision is where the application proves continuity between the browser step and the backend token exchange. Teams that treat the callback as inherently trustworthy tend to miss the control split between redirect handling, state validation, and PKCE binding.

Callback integrity is the real governance test. If the redirect URI can drift, the state value can be skipped, or the verifier can be mishandled, delegated access becomes fragile even when the overall OAuth design looks modern. Identity programmes should assess these controls together rather than as isolated implementation tasks.


For practitioners

  • Enforce exact redirect URI matching Register callback URLs precisely and reject any token exchange that does not return to the approved redirect URI.
  • Require PKCE on every client Use PKCE for confidential, mobile, and browser-based clients so the token exchange always depends on a verifier known only to the initiating app.
  • Validate state before exchanging codes Compare the returned state value with the stored request value before any code is sent to the token endpoint.
  • Keep client secrets server-side only Store client_secret values only in backend systems and never expose them in browser code, mobile bundles, or logs.
  • Shorten exposure windows for authorization codes Treat the code as a one-time credential and complete the token exchange immediately so intercepted codes expire before reuse becomes practical.

Key takeaways

  • OAuth authorization code flow reduces browser exposure by moving token issuance to a backend exchange, but it only works securely when the callback is tightly controlled.
  • PKCE makes intercepted authorization codes much harder to redeem because the token exchange must prove knowledge of the original verifier.
  • Redirect URI matching, state validation, and server-side secret handling remain essential controls, so OAuth security depends on implementation discipline as much as on protocol choice.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP API Security Top 10 and OWASP Non-Human Identity Top 10 address the attack and risk surface, while NIST SP 800-53 Rev 5 and NIST CSF 2.0 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
OWASP API Security Top 10API2 — Broken AuthenticationOAuth callback and token exchange failures can let attackers redeem intercepted codes.
API8 — Security MisconfigurationLoose redirect URI handling and callback trust are configuration failures in OAuth implementations.
Recommendation — Harden token exchange paths against intercepted credentials and invalid callback reuse. Enforce exact callback configuration and reject any redirect URI drift.
NIST SP 800-53 Rev 5IA-5 — Authenticator ManagementAuthorization codes, verifiers, and client secrets all behave like credentials with lifecycle requirements.
Recommendation — Manage OAuth credentials with strict issuance, storage, and expiry controls.
NIST CSF 2.0PR.AA-05 — Access Permissions, Entitlements and AuthorizationsThe article is about delegated access and authorization integrity across OAuth requests.
Recommendation — Apply authorization controls that bind delegated access to the intended app and session.
OWASP Non-Human Identity Top 10NHI-04 — Insecure AuthenticationOAuth codes and verifier binding are authentication controls for non-human access paths.
Recommendation — Treat OAuth tokens and verifiers as non-human authentication material that must be bound and protected.

Key terms

  • Authorization Code Grant: An OAuth flow that lets an application receive user-approved access without collecting the user’s password. The browser handles consent and redirection, while the backend exchanges a short-lived code for tokens. For identity teams, the control question is whether the exchange is bound tightly enough to the original request.
  • PKCE: Proof Key for Code Exchange is a binding mechanism that links the authorization request to the later token exchange. It helps stop authorization code interception and injection by requiring proof that the same client that started the flow is the one completing it.
  • Redirect URI: A redirect URI is the endpoint where an authorization server sends the user back after a login or consent step. In secure OAuth implementations, it must be pre-registered and matched exactly so an attacker cannot divert the response to a malicious destination.
  • State Parameter: A random value sent with an OAuth or OIDC authorization request and returned unchanged on the callback. It binds the browser redirect to the session that initiated it and helps prevent unsolicited callback injection. It does not validate the token itself or prove who redeemed the code.

Deepen your knowledge

NHI governance, agentic AI identity, and machine identity lifecycle are core topics in our NHI Foundation Level course, the industry's only accredited NHI security programme. If you are building or maturing an IAM programme, it is worth exploring.
NHIMG Editorial Note
Published by the NHIMG editorial team on June 8, 2026.
Updated on October 7, 2026.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org