The authorization request
When Ava selects Connect, the printer's first message is 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.: an authorizationDeciding whether a requested action is permitted, such as whether a signed-in account may delete a particular photo. Authentication says which account is asking; authorization decides what it can do. request that names the printer, the access it wants and where the answer should go. Every part of it is visible in Ava's browser, so it holds only public values and two protections for this one attempt.
Describing the request
Selecting Connect does not immediately give the printer access to Ava's photos. The request travels through Ava's browser to the authorization endpoint, as a redirect to a URL whose query carries the parameters. Here is the request used in our example, with its parameters on separate lines so we can read them:
https://auth.photos.example/authorize
?response_type=code
&client_id=photo-printer
&redirect_uri=https%3A%2F%2Fprinter.example%2Foauth%2Fcallback
&scope=photos.read
&state=demo-attempt-7
&code_challenge=qd-75t-gnweZAhIl6REjxxgFnPXGwvqYcxq3vlsaJYQ
&code_challenge_method=S256This is a fictional example, not a working connection. In particular, demo-attempt-7 is a readable stand-in for an unpredictable value generated for one attempt.
response_type=code asks the authorization serverIn OAuth, the service that handles a person's sign-in and approval and decides which tokens to issue to a client. It may belong to the same company as the API, but its job is separate. to return an authorization codeA short-lived, single-use value that the authorization server sends back to a client through the browser. The client swaps it for tokens in a direct request to the authorization server; APIs never accept it. if the request succeeds. It does not ask the server to put an access tokenA token that a client presents to an API to use access it has been granted, usually limited in what it allows and how long it lasts. It authorizes API calls; it does not tell the client who signed in. in the return URL.
client_id identifies the printer's registration. It is visible in the request and is not a secret, as Public and confidential clients explained. Another application knowing this value does not thereby become an authenticated instance of the printer.
redirect_uri tells the authorization server where to return the browser. The value is percent-encoded because it appears inside another URL, the encoding from Encoding and hashing: %3A is a colon and %2F a slash. Decoding it gives the printer's registered callback address.
scope describes the requested access. Here, photos.read is a permission name invented for our photo service, as in Grants, scopes, and consent. 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. does not define that particular name. If the service used different permission names, the printer would need to request those instead. Several scopes are separated by spaces, and a space in a URL is encoded as %20, so a request for two scopes reads scope=photos.read%20photos.write.
The last three parameters protect this one attempt. state is the random value the printer keeps in its pending transaction and expects to see again in the response, so it can connect the returning answer to the attempt it started. code_challenge comes from PKCEProof Key for Code Exchange, pronounced pixie: the client creates a secret for each authorization attempt, sends only a hash of it at the start, and proves it holds the secret when redeeming the code, so a stolen authorization code is useless to anyone else.: the printer makes a fresh secret verifier, keeps it, and sends only a value derived from it. code_challenge_method=S256 says how the challenge was derived: it is the SHA-256 hashTurning data into a short, fixed-size value called a hash, in a way that cannot be reversed and where changing one character changes the result completely. Services store password hashes instead of passwords, and signatures are made over a hash. of the verifier, base64url-encoded. A hash cannot be turned back into its input, so the challenge can travel in plain view while the verifier stays secret. Proof Key for Code Exchange (PKCE) and Correlating requests and responses follow each protection through the rest of the flow.
Requesting is not receiving
The printer chooses what to request. The photo service controls what it will allow. The requested scope must make sense for the service and the client registration, and the resulting access may be narrower than requested or refused entirely.
For the photo book, read access is enough. Requesting deletion access merely because it is available would make the connection more powerful without helping Ava complete this task.
The URL should contain only what belongs in this browser-facing request. The printer's client secretA shared secret that a confidential client uses to prove itself to the authorization server, much like a password for an application. It belongs on a backend, never in code sent to browsers or phones. and PKCE verifier stay on its backend. The photo service handles Ava's authenticationChecking evidence that someone, or some application, controls an account, such as a password or a passkey. It establishes which account is being used, not what that account may do. through its own interaction; the printer does not add her photo account password to this request.
When the photo service refuses a request, where it says so depends on how far its checks got. It checks the client ID and the redirect URI first. If either is unknown or does not match the registration, the server cannot trust the return address, so it shows its own error page in the browser and sends nothing back. Once both check out, it can safely return a refusal to the printer's callback instead of a code: an error parameter such as invalid_scope for a scope the registration does not allow, unsupported_response_type for a response type it does not offer, or invalid_request for a malformed parameter, together with the state the printer sent.
A request that passes every check is still only a request. The photo service now has to establish who is at the browser and whether to allow the access, which may mean a sign-in and a consent screen. The authorization endpoint is therefore a place to request and arrange access. Receiving a valid request there is the beginning of a decision, not evidence that the decision has already been made.
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
- Build the printer's authorization request one parameter at a timeWrite the printer's request in the lesson's layout, send it for Ava, then change one parameter at a time to see which mistakes stop at the tenant and which return to the printer, and let Ben ask without answering.