Trust boundaries
Every OAuthA framework that lets a person give an application limited access to their resources at another service, using tokens instead of sharing their password. OAuth is about access; OpenID Connect adds sign-in. message arrives from somewhere its receiver does not control. The printer, the authorization server and the photo API each have to check what reaches them before acting on it, and no one's checks can stand in for another's.
Crossing a boundary
The point where information passes between components with different control or authority is a trust boundary. When Ava connects the printer, information crosses three of them: the authorization server's answer reaches the printer through Ava's browser, the printer's code reaches the authorization server, and the printer's tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret. reaches the photo API. Each receiver asks its own questions, about its own decision from Roles and endpoints.
The printer receives the authorization response at its redirect URI. That address is public, and the response travels on the front channel, so anyone can make a browser open it with a code of their choosing. Receiving a request there proves nothing on its own. Before Ava's browser left, the printer generated a fresh random value called state, kept it with the pending attempt in Ava's sessionThe ongoing connection between later requests and an earlier sign-in, so you are not asked for your password on every click. It is often tracked with a cookie holding an unpredictable session identifier. at the printer, and sent it in the authorization request. The authorization server returns it unchanged:
GET /oauth/callback?code=SplxlOBeZQQYbYS6WxSbIA&state=af0ifjsldkj&iss=https%3A%2F%2Fauth.photos.example HTTP/1.1
Host: printer.exampleIf state does not match the value stored for this browser's attempt, the printer discards the response: it answers no attempt that this browser started. The iss parameter names the authorization server that sent the response, in the URL encodingWriting a character as % followed by a two-character code, such as %2F for /, so a value inside an address or form body is not mistaken for part of its structure. The receiving service decodes it before use. from Encoding and hashing. It matters when a client works with more than one authorization server, so a response from one is never taken for an answer from another. The printer checks it against the issuerThe party that creates and signs a token, assertion, or certificate, named in a token's iss claim. A recipient must check that the issuer is exactly the one it expected and trusts. it sent Ava to.
The authorization server has its own questions when the printer presents the code at the token endpointThe authorization server address where clients exchange an authorization code, refresh token, or other grant for tokens, in a direct request rather than through a browser redirect.. Is the redirect URI one registered for this client? Was this code issued to this client, and has it already been used or expired? Have the protections this exchange requires been satisfied, such as the one Public and confidential clients describes for clients that cannot keep a secret?
The photo API asks another set. Did an authorization server it trusts issue this token? Was the token intended for this API? Is it still usable? Does this request fall within the access granted, for this album?
Printing application
Authorization response
- Expected authorization attempt?
- Response matches the session?
Authorization server
Token request
code=ABC123
client_id=app123
redirect_uri=...
- Registered redirect URI?
- Code valid for this client?
- Code unused and unexpired?
Photo API
API request
access_token=...
album_id=789
- Trusted issuer and intended API?
- Token still valid?
- Access to this album allowed?
Protecting each request
The authorization server's decision to issue a token does not remove the API's responsibility to protect a particular album. The authorization server issued Ava's token without knowing which albums the printer would later ask for. Only the photo API sees that, request by request.
Suppose the printer, by a bug or by design, asks for album 4410, which belongs to Ava's friend Cora, using the token Ava approved:
GET /albums/4410 HTTP/1.1
Host: api.photos.example
Authorization: Bearer mF_9.B5f-4.1JqM
HTTP/1.1 404 Not Found
Content-Type: application/json
{"error": "not_found"}The token is genuine, current and meant for this API, and it worked a moment ago for Ava's album 4420. The API still refuses, because Cora has not shared album 4410 with Ava. It answers 404, exactly as it would for an album that does not exist, so the refusal does not even reveal that the album is there. A valid token says who is asking and with what access; it is not permission to read whichever identifier appears in a URLA web address, such as https://photos.example/api/albums/42?limit=10. It names how to connect (https), the domain, the path to a particular page or resource, and any extra parameters after the question mark.. The API checks this person against this object on every request.
Checking a token is a separate step that comes first. Some access tokens are opaque: random-looking values with no readable content, whose meaning the API learns by asking the authorization server, a lookup called introspection. Others are signed JSONA text format for structured information, written as named values inside curly braces. APIs, tokens, and discovery documents all use it. Web Tokens that the API checks itself. For a JWTA JSON Web Token: a compact token made of Base64url-encoded parts that carries claims and is usually signed. Anyone holding it can decode and read the claims, so the signature shows who issued it but hides nothing., Digital signatures showed that the signatureA value made with a private key that lets anyone holding the matching public key check that a message came from the key's holder and has not been changed. It proves origin and integrity; it does not hide the message. is only one part: the API also checks the issuer, the audience, the token type and the lifetime. A correctly signed token from the same authorization server, but addressed to another API, must be refused:
Decoded payload of the token the printer sent
{
"iss": "https://auth.photos.example",
"aud": "https://api.printlab.example",
"scope": "photos.read"
}
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer error="invalid_token"The audience names the print lab's API, not the photo API, so the photo API refuses it before it looks at any album. Accepting it would let a token issued for one service be replayed at another.
Transport protection solves a different part of the problem. HTTPSHTTP protected by TLS, so traffic is encrypted and checked for changes while it travels. It protects the connection, but does not prove that the site at the other end is honest. protects these messages while they travel between two endpoints. It does not show that the printer was entitled to a particular album, that a code belongs to this client, or that an authorization response matches the browser session receiving it. Likewise, reading a token's contents does not establish that they are trustworthy. Each of those needs its own check, at the boundary where the decision is made.
After access is granted
There is one more boundary, after the photo API has said yes. Once the printer downloads Ava's photos, it holds copies. When Ava disconnects the printer, the photo service refuses its future requests, but that cannot make the copies already downloaded disappear. For those, Ava is trusting the printer itself: its storage, its retention and its promises about what it does with her photos.
These boundaries are why an OAuth integration needs more than a successful happy path. A connection where every message arrives as expected shows only that nothing went wrong this time. The checks show what happens when a response was never requested, a code was copied, or a token arrives at the wrong API. Later lessons introduce each set alongside the exchange it protects: the printer's in Correlating requests and responses, the authorization server's in Redirects and authorization codes and Exchanging a code for tokens, and the photo API's in Token formats and validation.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Decide, as the photo API, whether to trust a tokenRead the checks the client and the authorization server made, then see the photo API refuse another user's album and a correctly signed token meant for another API.