Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Redirects and authorization codes

Once the photo service has finished with Ava, it redirects her browser back to the printer with the result in the address. That address carries a credential, so the photo service sends it only to a return address registered exactly, and the printer handles the code it receives as something to protect and redeem, never to read.

Choosing the return address

Imagine changing the delivery address on a parcel after someone has packed it. It would not help to pack the right item if it then went to the wrong recipient. Similarly, a correctly issued authorization code can be exposed if the server sends it to an untrusted address.

The printer's request named its return address in redirect_uri, but anyone can write any value into a URL. So the photo service compares the requested redirect URI with the addresses registered for the printer, character for character. For a web client like the printer this is exact matching: a different path, a changed letter or an added or missing trailing slash makes a different address, and the server rejects it. Accepting anything that begins with the printer's hostname is not a substitute for this check, because other pages on the same site, or on a lookalike site, could then collect codes.

Our example registers one HTTPS address:

https://printer.example/oauth/callback

Registered for the printer

https://printer.example/oauth/callback

Requested as registered

redirect_uri
/oauth/callback
Matches
Character for character
Server answers
Redirect with the code

Code goes to the printer

One character added

redirect_uri
/oauth/callback/
Matches
No
Server answers
Its own error page

Nothing is sent back

Unregistered host

redirect_uri
example.com/callback
Matches
No
Server answers
Its own error page

Nothing is sent back

Accepting anything that begins with the printer's hostname is not a substitute for this check.

The photo service compares each requested return address with the one the printer registered. Only the exact address receives a redirect; for the others it shows its own error page and sends nothing back.

When the address does not match, the server cannot know who controls it, so it does not redirect there at all, not even with an error. It shows its own error page in the browser instead. Installed applications receive the response in other ways, such as loopback addresses whose port is allowed to vary. Redirect URIs and client metadata, in Clients and registration, covers those cases rather than stretching this web example to fit them.

Returning the response

Once Ava has signed in and the photo service has decided to allow access, it answers her browser with a redirect. A successful response in our example looks like this:

HTTP/1.1 302 Found
Location: https://printer.example/oauth/callback?code=demo-code-7&state=demo-attempt-7&iss=https%3A%2F%2Fauth.photos.example
Cache-Control: no-store

As How applications communicate showed, the browser follows the Location address with a new request, so the code is carried in the query string of the request to the printer. Cache-Control: no-store tells the browser and any cache along the way not to keep a copy of this response, which holds a credential.

Do not treat every redirect status as equivalent. After a 302 or 303, the browser sends a fresh GET to the new address. A 307 or 308 instead repeats the original method and body. If a sign-in endpoint answered a password POST with such a redirect, the browser could forward the submitted password to the redirect destination. A server must choose a status that changes a credential submission into a safe GET, rather than depending on the destination to discard the body.

iss names the authorization server that sent the response, the issuer from Roles and endpoints. It comes from an extension to OAuth called authorization response issuer identification, so not every authorization server includes it. Our photo service does, and Correlating requests and responses explains how the printer checks it.

state carries back the value from the authorization request. The printer must validate it against its pending transaction. The presence of familiar-looking parameter names does not make a callback trustworthy. A refusal returns the same way, with an error parameter in place of the code, and the printer checks it just as carefully.

The photo service checks the registered return address before redirecting. The browser carries code, state, and issuer to that address. The printer backend must validate the response before exchanging the code.

Handling the code

The code is short-lived and single-use. The photo service records which client it was issued to, which redirect URI the request used and, in this flow, the PKCE challenge, and checks all of them when the code is redeemed. The printer should treat its contents as opaque: often it is just a random string, so the printer presents it to the token endpoint rather than trying to decode an account identifier or permissions from it.

Codes still need protection. A callback URL can end up in analytics, request logs, browser history or the Referer header, the leaks Why use the authorization code flow? listed. Keep the callback focused on processing the response, avoid third-party resources there, send Referrer-Policy: no-referrer, and move the browser to a clean application URL after handling it. Do not record the full callback query in application logs; record the outcome instead.

Using a code creates an opportunity for the token endpoint to perform additional checks before issuing an access token. It does not make redirect validation or credential handling unnecessary.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

The printer registered /oauth/callback, but a request supplies /oauth/callback/. What should the server do for this web client if only the first address is registered? 1 of 3

Choose one answer.

Why should the printer avoid logging the entire callback URL? 2 of 3

Choose one answer.

Ava submits her password to the photo service's sign-in form in a POST, and the server answers with a redirect. Which answer keeps her password from being sent on to the next address? 3 of 3

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity