Handbooks / REST API Design / Chapter 3
Authentication and Authorization
7 pages · ~5 min✓ Reviewed
Builds on Resource Design. Next up: Versioning and Pagination.
API Keys, Sessions and Tokens
1. Authn vs Authz
| Authentication | Authorization | |
|---|---|---|
| Asks | Who are you? | What may you do? |
| Fails | 401 | 403 |
2. Three Credentials
- API key: static secret naming an app
- Header
X-API-Key: <key>orAuthorization: Bearer <key>, never the URL - Session: server stores state, cookie holds opaque ID; revoke = delete record
- Token: signed, self-contained, no server record; scales, hard to revoke before expiry
| API key | Session | Token | |
|---|---|---|---|
| Is | machine identity, no user | stateful, cookie-bound | stateless, carries claims |
| Life | long-lived | server decides | short-lived |
| Revoke | rotate | easy | hard |