OpenBook
  • Problems
  • Tracks
  • How it works
  • Pricing
Start practicingSign In
Problems/Auth & Permissions

24. API Keys with Scopes and Rotation

Medium

Issue scoped API keys that are shown once and stored hashed, guard routes by scope, and rotate or revoke keys without downtime.

40 minute budget0.0% acceptanceAPI keys · scopes · key rotation · hashing

Requirements

  1. 01POST /accounts/:account/keys { name, scopes } creates a key (201) and returns a random secret; store only its sha256 hash. Invalid name or scopes is a 400.
  2. 02Scopes are "<action>:<resource>" strings with action read or write. GET /projects needs read:projects and POST /projects needs write:projects; the key travels in the x-api-key header.
  3. 03GET /accounts/:account/keys lists every key of the account, oldest first. A key id from another account is a 404.
  4. 04POST .../keys/:id/rotate issues a replacement key (201) while the old one keeps working for a while; POST .../keys/:id/revoke stops a key immediately.
  5. 05Projects belong to the key's account. Time comes from the x-now header when present.

What the hidden tests check

  • Everything the interviewer tells you is checked.
  • Old, revoked and under-scoped keys are each probed on both protected routes, at controlled times.

4 more details are held back. In a mock interview they come out only when you ask the interviewer the right question; in practice they are listed in the workspace.

Sign in to start

Attempts, files and transcripts are saved to your account so the grader can review how you worked.

Sign inCreate an account
OpenBook

Practice for interviews where you build a feature with an AI assistant.

Early preview. Problems, grading and the interviewer are still changing.

Practice

  • Problems
  • Tracks
  • How it works
  • Pricing

Legal

  • Terms
  • Privacy
© 2026 OpenBook.