Join our Newsletter — 33% off our NHI Course

How does the OAuth 2.0 authorisation code flow work with Microsoft Entra ID?

The OAuth 2.0 authorisation code flow has Microsoft Entra ID authenticate the user, then return a short-lived code to the client, which exchanges it for tokens. This keeps tokens off the front channel and is the preferred pattern for web and native apps. Practitioners should require redirect URI matching, use PKCE where applicable, and validate issuer, audience, and expiry on received tokens.

How the authorisation code flow fits Microsoft Entra ID

microsoft entra id acts as the authorisation server and the user’s identity provider in this flow. The client sends the user to Entra ID, the user signs in there, and Entra ID returns an authorisation code to the client’s redirect URI. The client then redeems that code directly at the token endpoint, which is what keeps tokens off the browser front channel.

For web apps, this separation matters because the browser only carries the short-lived code, not access or refresh tokens. In Microsoft environments, that design aligns with the platform’s modern app model and is the safer default for apps that can maintain a server-side component or use a native app redirect pattern.

When implemented correctly, the flow also gives you a clean place to enforce expected issuer, audience, and expiry checks on the tokens that come back from Entra ID. That validation step is not optional, because the client is trusting a token issued by an external authority, even when the authority is Microsoft-managed.

What must be validated in a Microsoft Entra ID integration

The most important implementation controls are the ones that bind the returned code and tokens to the intended application instance. Redirect URI matching prevents a code from being delivered to the wrong endpoint, and PKCE strengthens the exchange for public clients and other cases where a client secret is not appropriate. The token exchange should always be tied to the exact app registration and redirect configuration you expect.

OpenID Connect is commonly layered on top of this flow when the app needs user identity as well as delegated API access. If you are using Entra ID for sign-in, make sure you are clear about whether the app is consuming an ID token for authentication, an access token for API calls, or both. Confusing those token types is a common source of logic errors and broken trust decisions.

If the application is a confidential client, the code exchange should happen on the server side with a protected credential path. If it is a native or mobile client, the design should assume the secret cannot be safely hidden and rely on PKCE and the app platform’s recommended redirect mechanism rather than trying to force a browser-only pattern into a trusted-server shape.

Where failures usually happen in real deployments

The flow is strong only when the redirect URI, client registration, and token validation are all strict. Loose redirect handling, skipped issuer checks, or accepting tokens for the wrong audience can turn an otherwise standard sign-in flow into a token substitution problem. That is why the security posture is as much about correct app registration as it is about the protocol itself.

Threat actors often target the edges of the flow rather than the protocol core. A fraudulent app registration, consent abuse, or a stolen authorisation code can still lead to account access if the surrounding controls are weak. The Microsoft verified publisher OAuth phishing 2022 case shows how user trust in an OAuth consent screen can be turned into persistent mailbox access.

Another practical failure mode is overreliance on the fact that the code is short-lived. Short-lived does not mean harmless if an attacker can intercept it, race the legitimate client, or use it before the exchange completes. For that reason, the implementation should assume code theft is a meaningful threat and use the strongest available binding and validation controls.

Risk and Threat Considerations

The main risk is not the authorisation code itself, it is the trust chain around it. If an attacker can alter the redirect, steal the code, abuse consent, or register a malicious app against the tenant, the flow can be used to obtain valid tokens and then operate as the user or application.

Failure mechanism: Weak redirect validation, missing PKCE, or poor token audience and issuer checks let an attacker turn a normal sign-in sequence into token theft, consent abuse, or application impersonation.

Impact: The result can be account takeover, unauthorized API access, mailbox or data exposure, and persistent access that looks legitimate to downstream services.

Standards & Framework Alignment

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

NIST SP 800-63, NIST SP 800-53 Rev 5 and OWASP ASVS set the governance and control requirements practitioners need to meet.

Framework Control / Reference Relevance
NIST SP 800-63 Digital Identity Guidelines Covers authentication flow assurance and token-based sign-in trust decisions.
Recommendation — Apply digital identity guidance to validate issuer, audience and token lifetime before granting access.
NIST SP 800-53 Rev 5 IA-2 — Identification and Authentication (Organizational Users) Authorisation code flow depends on strong user authentication before token issuance.
IA-5 — Authenticator Management The flow relies on managed credentials, codes and token handling across the client boundary.
SC-23 — Session Authenticity Redirect and code handling must preserve authenticity across the browser-to-token exchange.
Recommendation — Require strong user authentication before issuing tokens through Entra ID. Protect and manage client authenticators, codes and token handling with strict lifecycle controls. Bind the authorization response to the intended client and reject unauthenticated redirects.
OWASP ASVS V10 — OAuth and OIDC Directly addresses OAuth/OIDC implementation requirements for authorization code flow and token validation.
V6 — Authentication Covers sign-in assurance and identity verification before tokens are accepted.
Recommendation — Implement OAuth and OIDC checks for redirect handling, PKCE and token validation. Verify authentication results before trusting received identity tokens.

Practitioner Guidance

What to verify: Check that each Entra ID app registration has an exact redirect URI list, that the token endpoint only accepts the intended client type, and that your validation logic rejects unexpected issuer, audience, or expiry values. If the application is public-facing or native, confirm that PKCE is enforced wherever the client cannot safely protect a secret.

Common mistake: Teams often test the happy path and stop there. In practice, the dangerous gap is when the app accepts a token that is technically valid but not valid for that app, or when a consented app has more reach than the business intended.

Practitioner takeaway: Treat the authorisation code flow as secure only when registration hygiene, redirect control, and token validation are all enforced together; weakening any one of them reintroduces front-channel and token-abuse risk.