OAuth and login providers · Design
Design API keys for partners
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe interviewer asks
Design API keys for our partner API: how they're created, shown, stored, sent, checked, limited and rotated.
Then
Follow-ups the interviewer asks next
- What does a key look like, and why a prefix?
- Why store a hash, and which hash?
- How does the server find the key's owner quickly if it only has a hash?
- Header or query string?
- How does a partner rotate a key without downtime?
- A partner's key turns up on GitHub. What happens?
- When would you use OAuth client credentials or request signing instead?
The answer
What a strong answer covers
- Format: a prefix with the environment (
pk_live_,pk_test_), a short public id, and 32 or more random bytes in base62. The prefix lets secret scanners and people recognise it. - Shown once at creation; stored as a SHA-256 hash (fine for long random keys; slow password hashes are for guessable passwords) next to the public id used for lookup.
- Sent in a header (
Authorization: Bearer …orX-API-Key), never in the URL, where it ends up in logs and browser history; HTTPS only. - Check: look up by id, compare hashes in constant time, load the owner, scopes and status; cache briefly so a revoked key stops working within seconds.
- Limits: per-key rate limits and quotas (a token bucket in Redis), 429 with
Retry-After, and a usage dashboard. - Rotation: two active keys per partner,
last_used_atshown so they know when the old one is unused, optional expiry dates. - Leaks: join GitHub's secret scanning partner programme so leaked keys are reported automatically; revoke, tell the partner, and check the usage logs.
- Scopes and environment per key, optional IP allowlists, audit logs of creation and use, and never logging keys.
- Stronger options for high-value APIs such as payouts: OAuth client credentials (short-lived tokens, standard tooling) or HMAC request signing, where the secret never travels.
The red pen
Common traps
Avoid:keys stored in plain text; keys in query strings; one key per partner forever.
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voicePractise questions like this out loud
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.