Q7: Explain the OAuth 2.0 Authorization Code Flow with PKCE.
Difficulty:AdvancedTopic:OAuth Grant Flows
Proof Key for Code Exchange (PKCE, RFC 7636) secures the Authorization Code flow for public clients (SPAs, Mobile Apps) against authorization code interception attacks.
PKCE Protocol Steps:
- Client creates a random string
code_verifierand computescode_challenge = BASE64URL(SHA256(code_verifier)). - Client redirects user to Authorization Server passing
code_challengeandcode_challenge_method=S256. - User authenticates and grants access; Authorization Server redirects back with an
authorization_code. - Client exchanges
authorization_code+ originalcode_verifierat the token endpoint. - Authorization Server hashes the provided
code_verifierand verifies it matches the storedcode_challengebefore returning access tokens.
OAuth 2.0 Authorization Code Flow + PKCE Sequence
Key Takeaways
- PKCE replaces client secrets for public clients (Mobile apps, Single Page Applications).
- The authorization code cannot be exchanged for tokens without presenting the matching unhashed
code_verifier.