Authentication¶
Overview¶
Authentication establishes who is calling; authorization decides what they may do. Web APIs commonly use sessions, API keys, and tokens (often JWTs) with OAuth2/OIDC for delegated login.
Why This Exists¶
Trust boundaries fail without strong identity. Password handling, token lifetimes, rotation, and revocation separate toy demos from production systems.
How It Works¶
Study password hashing (Argon2/bcrypt), MFA, OAuth2 flows (authorization code with PKCE for SPAs), JWT structure (claims, signature, audience), refresh tokens, revocation lists, and service-to-service credentials (mTLS, workload identity).
Architecture¶

Key Concepts¶
Code Examples¶
verify_signature(token, jwks)
assert iss == expected_issuer
assert aud contains our_api
assert exp > now
check nbf if present
Interview Questions¶
What is the difference between OAuth2 and OpenID Connect?
OAuth2 delegates authorization to access resources; OIDC adds identity tokens and standard userinfo on top of OAuth2.
Why use PKCE?
Prevents authorization code interception for public clients by binding the token exchange to a code verifier.
Practice Problems¶
- Threat-model storing refresh tokens in mobile secure storage vs browser
- Compare session cookies vs bearer tokens for same-site vs cross-site APIs