Part 04 / Topic 2 of 6
Authentication schemes
Three schemes cover almost every customer API, and you need them at concept level before touching code:
- API key — a static secret, usually in a header (
X-API-Key: ...). Simple; rotate it if it leaks. - Bearer token —
Authorization: Bearer <token>. The token may be long-lived (like Acme's) or short-lived and refreshed. - OAuth 2.0 client credentials — your service exchanges a client id + secret for a short-lived access token, then sends that as a bearer token. The flow exists so the long-lived secret is used rarely and the thing sent on every request expires quickly.
What matters operationally is the same for all three: the secret comes from the environment or a secret manager (Part 2), it never appears in logs (Part 12), and a 401 means fix the credentials, while a 403 means you are authenticated but not allowed — ask for permission.
🧪 Quick quiz
- What is the difference between 401 and 403?
Show the answer
401: not authenticated (missing or bad credentials). 403: authenticated but not allowed. 401 means fix the credentials; 403 means ask for permission.
Done here? The practice set for Part 4 — 4 exercises with solutions — is on the part page.