Problem
Apps need delegated access to APIs, but passing passwords to every client is unsafe. Public clients such as SPAs and mobile apps cannot keep a client secret, so a stolen authorization code could be redeemed by an attacker.
Also known as: oidc-code-flow, pkce
Let a client obtain tokens on a user's behalf without ever handling the user's credentials, safely even for public clients.
Apps need delegated access to APIs, but passing passwords to every client is unsafe. Public clients such as SPAs and mobile apps cannot keep a client secret, so a stolen authorization code could be redeemed by an attacker.
Authorization Code with PKCE is the recommended OAuth 2.0 flow for nearly every interactive client. OAuth handles authorization (what an app may do); OpenID Connect layers an ID token on top to handle authentication (who the user is). PKCE binds the code to the client instance that started the flow.
In practice, adopt a certified library or managed identity provider rather than hand-rolling the protocol. Most vulnerabilities come from integration mistakes, not the specification, so test redirect handling, token storage and logout behavior explicitly, and review the provider security best-practice guidance whenever you add a new client type.
Client: verifier = random(64B); challenge = BASE64URL(SHA256(verifier))
Client -> AS /authorize?response_type=code&client_id=..&redirect_uri=..
&scope=openid profile&state=xyz
&code_challenge=..&code_challenge_method=S256
User authenticates at AS, consents
AS -> Client redirect_uri?code=abc&state=xyz
Client -> AS /token grant_type=authorization_code, code=abc, code_verifier=verifier
AS: SHA256(verifier) == challenge ? issue access + ID + refresh token
The client validates state, then validates the ID token signature, issuer, audience, nonce and expiry before trusting it.
Medium — IdP or managed identity service
Medium — key rotation, client registration
High — many parameters and flows
Open or wildcard redirect URIs leak codes
Missing state check enables login CSRF
Refresh tokens stolen from local storage