QA
Intermediate LevelREST APIs & Web Services

How does the OAuth 2.0 Authorization Code Grant Flow with PKCE operate?

❓ Interview Prompt: Explain OAuth 2.0 PKCE (Proof Key for Code Exchange), Code Verifier, Code Challenge, Authorization Code, Access Token, and securing public SPA/mobile apps.

OAuth 2.0 Authorization Code Flow with PKCE (RFC 7636) is the gold standard authentication framework for single-page apps (SPAs) and mobile devices:

PKCE Security Mechanics:

1
Code Verifier: Client generates a cryptographically random secret string.
2
Code Challenge: Client creates a SHA-256 hash of the verifier ('BASE64URL(SHA256(verifier))').
3
Auth Code Request: Client redirects user to authorization server passing 'code_challenge'.
4
Token Exchange: Client exchanges auth code for JWT tokens by passing the original 'code_verifier' secret. The server hashes it and verifies match, preventing authorization code interception attacks!

Code Implementation Example

typescript
import crypto from 'crypto';

// Generate PKCE Code Verifier & Code Challenge
const codeVerifier = crypto.randomBytes(32).toString('base64url');
const codeChallenge = crypto
  .createHash('sha256')
  .update(codeVerifier)
  .digest('base64url');

console.log({ codeVerifier, codeChallenge });
💡Generating OAuth 2.0 PKCE code verifier and challenge strings in TypeScript.
🎯 Interview Key Takeaway

Use OAuth 2.0 Authorization Code Flow with PKCE to secure public SPA and mobile API clients against token interception.

#OAuth 2.0#PKCE#Security#Tokens#Intermediate
Back to all REST APIs & Web Services Questions→

More REST APIs & Web Services Interview Questions

Beginner LevelREST APIs & Web Services

What is HTTP Method Idempotency and how do you implement Idempotency Keys for REST APIs?

Beginner LevelREST APIs & Web Services

What are standard HTTP Status Codes (200, 201, 204, 400, 401, 403, 404, 409, 429, 500, 503)?

Beginner LevelREST APIs & Web Services

What are HTTP Verbs (GET, POST, PUT, PATCH, DELETE) and when to use PUT vs PATCH?