OAuth 2.0 and PKCE
We give one application limited access without sharing the user’s password. A token response alone does not prove the intended login identity. We will trace OAuth roles, the authorization-code flow, PKCE, and consent and refresh boundaries.
#Section 13Delegation is a different problem from login
Mira wants a clip-analysis application to read selected Heron media without learning her Heron password. OAuth 2.0 is an authorization framework for delegated access. A client obtains a credential granting a defined scope to a resource service under an authorization server’s policy.
The resource owner controls the relevant access, the client requests delegated access, the authorization server issues the grant and tokens, and the resource server enforces access to the API. These roles can share deployment infrastructure but have distinct responsibilities. A client identity is not the same as the user identity it represents.
Scope describes the permitted use of a grant, with semantics defined by the service. A token with read scope still needs resource ownership and tenant checks. Scope is not a universal string whose name automatically enforces a policy. The API must map it to actual allowed actions.
#Section 14The authorization code is exchanged at another boundary
The client sends the user to the authorization server with a registered redirect URI and flow context. The user authenticates there and approves the requested access under policy. The server returns an authorization code, a short-lived one-use value, through the redirect. The client exchanges that code at the token endpoint under the flow’s client and proof rules.
The browser redirect carries a code rather than treating the redirect URL as a permanent API credential. The authorization server checks that the redemption matches the intended client, redirect URI, and grant context. A confidential client authenticates as required; a public client cannot keep a secret merely because its source code contains one.
The code exchange should occur through the intended secure endpoint and registered flow context. A client must not send the code to an arbitrary token URL supplied by untrusted input. The browser-facing redirect and server-facing exchange therefore have different validation responsibilities. Logging their full URLs can also expose sensitive one-use values during the flow.
OAuth’s security best current practice, RFC 9700, documents secure flow choices and redirect, token, and client concerns. Follow current provider documentation for implementation. Do not invent a homegrown redirect matching rule or reuse the user’s password as a client credential.
#Section 15PKCE binds redemption to the initiating client
An attacker intercepts an authorization code. If that code can be redeemed alone, the attacker can obtain the resulting credential. Proof Key for Code Exchange, or PKCE, binds the code exchange to a secret value generated for this authorization attempt. The client creates a verifier and sends a derived challenge in the authorization request.
At redemption, the client supplies the verifier. The authorization server recomputes the challenge under the required method and compares it with the value associated with the code. Someone holding only the intercepted code lacks the verifier. The challenge is not a reusable client secret and must be created and bound correctly for each attempt.
The client also binds the browser response to its initiating context and validates expected authority and redirect behavior. A state parameter can carry a protected unpredictable correlation value for the flow under a reviewed protocol. OpenID Connect adds identity-specific rules, including nonce where applicable. Do not treat any one parameter as a complete defense for every flow confusion.
#Section 16Grants, refresh, and revocation need policy
Mira removes the clip-analysis application’s access. The authorization server stops renewal and revokes the relevant grant according to policy. Existing access tokens may remain accepted until expiry unless the resource server checks current grant validity. That is the same local-validation tradeoff discussed earlier, now applied to delegated access.
A consent record captures approved access under the service’s user and client policy. A refresh credential should remain scoped to that grant and protected against copying. Rotation or sender-constraining mechanisms can limit replay under the chosen design. A long-lived credential in a public repository or browser log defeats the separation delegation was meant to provide.
Least-scope requests improve user comprehension and limit damage. Do not request all media writes when the app only reads a chosen clip. Client registration, redirect restrictions, token storage, and resource enforcement are part of the architecture. In an interview, draw the browser, client server, authorization server, and API separately so their credentials do not become interchangeable.