API Authorization 00:00:01 Start with roles A customer is signed in and asks for an order. The store knows exactly who she is. It still has to ask whether this particular order belongs to her and whether this action is allowed here. Customers view products and place orders. Cart and orders are their own only. Sellers create products, edit their own, and see their own sales. They cannot delete. Admins hold the wildcard, so every row is yes. Give this role to very few people. Someone who is a customer and a seller gets the union. Nothing is taken away. Edit product says own for sellers. The role can say that much and no more. A role groups permissions to simplify policy. Resource ownership can still matter inside the same role, because two customers are allowed to read different orders. 00:00:47 Check the actual resource The customer role has products:read. Granted. No customer permission says delete. Denied before the data is touched. The role says own, and Mike owns the lamp. Granted. The same role, but the chair belongs to Jane. Denied. The wildcard covers it. Granted, and recorded in the audit log. Test both the action and the object it names. Checking a route once for the customer role cannot answer which individual order the authenticated person may inspect. 00:01:16 Keep checks at the boundary A seller updates a product: three checks, in order. A seller sends PUT /products/42 with a token. The token is verified. Without a valid one the answer is 401. The seller role has products:update:own, so the endpoint is open to them. Otherwise 403. The handler reads product 42 within the seller's tenant. The owner is this seller, so the update is saved. Product 43 belongs to someone else. The same request now ends as 404. Middleware can establish shared identity and enforce common policy. The service that knows the resource may still need to decide ownership or current state immediately before returning or changing it. 00:01:59 Delegate limited partner rights A user lets another app do two things, and no more. The partner app asks for products:read and cart:write. The user sees the list and allows it. Payment details are not on it. The app receives a token with exactly those scopes. Scope held, and the user may change this cart. Allowed. The scope was never granted. Refused at the API. Give an integration only the scopes it needs and apply the user's own resource restrictions too. A broad partner identity should not enlarge what that user is allowed to see. 00:02:30 Protect the authenticated customer's order The most common authorization hole, and its fix. Ann asks for order 1001, which is Ann's. Ann changes the number. The server checks only that they are logged in, so Ben's order is returned. The query now needs the caller's ID from the token. Order 1002 is not found for Ann. Use the authenticated identity and the stored resource owner to decide access. Consistent error behavior limits how much private resource existence is disclosed to unauthorized callers. 00:03:00 Revoke a role already in use Why a copy of a role goes stale. The token issued at 12:00 says admin, until 12:15. The database changes. The token does not. Dangerous actions ask the database, so they stop at 12:05. The rest stops at 12:15. A role embedded in a previously issued credential can outlive a permissions change. Define whether sensitive actions consult fresh policy, and measure the delay before revocation becomes effective. Authorization binds a caller, a resource, an action and a context. A convincingly authenticated identity can still receive a perfectly correct refusal.