Who is calling: keys and tokens
Authentication answers 'who is calling?'; authorization answers 'may they do this?'. Two common ways to authenticate an API call:
API keys identify an application or account: a long random secret, sent in a header, used for server-to-server calls. Bearer tokens are short-lived credentials, usually issued through OAuth 2.0, sent as Authorization: Bearer <token>. They identify a user (or a service acting for one), expire after minutes or hours, and can be revoked.
Rules for both: only over HTTPS; in a header, never in the URL (URLs end up in logs, browser history and Referer headers); store only a hash of API keys on the server, like passwords; and allow keys to be rotated without downtime.
Stripe uses secret API keys for server calls; GitHub accepts personal access tokens and OAuth tokens in the Authorization header and lets users revoke them individually.
In code: HTTP
GET /v1/orders
Authorization: Bearer eyJhbGciOiJSUzI1NiJ9…
→ 200 OK
GET /v1/orders # no credentials
→ 401 Unauthorized
WWW-Authenticate: Bearer
GET /v1/orders?api_key=sk_live_… # don't: the key leaks into logs- 401 must include a WWW-Authenticate header saying which scheme to use (RFC 9110).
- Bearer means whoever holds the token can use it, which is why HTTPS and short lifetimes matter.
Which practices are right for API credentials? (Choose three.)
Select 3, then check.