liveBook · Manning

Authorization

As explained in API Design Patterns

Authorization is the determination of whether an authenticated user is permitted to perform a requested operation.

Access control determines which resources an authenticated requester may see or operate on. For collection listings, consistency does not require identical responses: each requester should receive only the resources they can access. section 7.3.4

Apply access control to collection listings with these rules:

  • Filter the response to resources available to the requester, so two people listing the same collection may receive different results. section 7.3.4
  • When possible, structure resources to avoid mixed-access collections; a secured collection can then return 403 Forbidden. section 7.3.4
  • Do not assume every list request can use a single response for every requester when permissions differ by item. section 7.3.4

Chat rooms and messages

A list request for ChatRoom resources targets /chatRooms. A request for messages under one room targets /chatRooms/{id}/messages. If a requester can access only some rooms, the response contains only those rooms rather than exposing the full collection. section 7.3.4

Listing 7.2 An example of the standard list method
abstract class ChatRoomApi {
  @get("/chatRooms")                                                #1
  ListChatRooms(req: ListChatRoomsRequest): ListChatRoomsResponse;
 
  @get("/{parent=chatRooms/*}/messages")                            #2
  ListMessages(req: ListMessagesRequest): ListMessagesResponse;
}
 
interface ListChatRoomsRequest {
  filter: string;
}
 
interface ListChatRoomsResponse {
  results: ChatRoom[];
}
 
interface ListMessagesRequest {
  parent: string;
  filter: string;
}
 
interface ListMessagesResponse {
  results: Message[];
}

Use the API listing to compare top-level ChatRoom listing with nested Message listing, including request filters and result collections. section 7.3.4

How API Design Patterns covers it

How deep it goes
Explains requester-dependent filtering and contrasts it with 403 responses, without detailing broader access-control mechanics.
Examples
Uses ChatRoom and nested Message collections to illustrate different requester-visible results.
What you can do after
Apply it by returning only authorized resources when listing a collection containing mixed-access items.
How it connects
Connects access control to list methods, resource collections, nested resources, and 403 Forbidden responses.

Also explained in

Compare how 28 books explain authorization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of API Design Patterns. The section links point to the parts of the book it draws on.