liveBook · Manning

Authorization

As explained in The Design of Web APIs, Second Edition

Access control consists of rules and mechanisms that determine which subjects may access particular API resources or operations.

Authorization determines which applications and end users may call an API operation, access a resource, or see particular data. Define “who can see and do what” during API design: a valid token alone does not establish permission to perform every action. section 1.7.3 section 12.10.2

An application’s scope can grant access to an operation, while end-user permissions and business rules still determine whether the request succeeds. For POST /transfers, an API gateway can reject an application without the transfer scope. The implementation can then reject a transfer over $100,000 if the user lacks the required permission—or reject it because the account has insufficient funds. section 12.7.1

Choose an error that fits what may be disclosed

A GET /accounts/12345 call without a required consumer scope can return 403 Forbidden. A bank advisor who does not manage that account may also receive 403 if requesting additional permission is possible. For an account holder who does not own it, return 404 Not Found when revealing that the account exists would be inappropriate. An error message can identify a missing scope, but doing so discloses more than a generic “Missing scope” message. section 12.10.2

Make authorization rules visible in the API description as well as enforce them. OpenAPI operation descriptions can state who may make a transfer; property descriptions can state that a transaction’s merchant address is returned only to account owners. If one operation combines routine transfer edits with employee validation of unusual transfers, a separate validation operation makes the sensitive action easier to identify and control. section 12.4.4 section 12.3.4

As a design check, consider GET /patients/{patientId}/conditions: several hospital applications use the same API, but only treating doctors using Patient Folder or Treatment should access the data. Ask which restrictions concern the application and which require an implementation check of the end user’s relationship to the patient; an operation scope alone does not guarantee execution. section 12.15 section 12.7.1

How The Design of Web APIs, Second Edition covers it

How deep it goes
Works through gateway and implementation checks, response choices, and documentation guidance without specifying authorization algorithms.
Examples
Uses bank transfers, account reads, permission-dependent transaction fields, and a hospital patient-conditions exercise.
What it assumes
Assumes familiarity with API operations and HTTP requests while explaining how scopes and end-user permissions differ.
What you can do after
Apply it via API gateway scopes and implementation checks, documenting restrictions and choosing 403 or 404 according to disclosure needs.
How it connects
Connects OAuth scopes, API gateways, tokens, end-user permissions, business rules, HTTP status codes, and OpenAPI descriptions.

Also explained in

Compare how 32 books explain authorization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Design of Web APIs, Second Edition. The section links point to the parts of the book it draws on.