Beta

Create a tenant

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

BTL Admin

Redirects and authorization codes

After the photo service finishes its interaction with you, your browser needs to return to the printer. The return address matters because the response can contain a credential.

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.

Choosing the return address

For this web client, the photo service compares the requested redirect URI against the addresses registered for the printer using exact matching. A different path or an added 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.

Our example uses HTTPS:

https://printer.example/oauth/callback

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

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

The browser follows the Location address. The code is carried in the query string of the resulting request to the printer.

iss names the authorization server that sent the response. 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.

The photo service checks the registered callback before redirecting. The browser carries code, state and issuer to the printer backend, which validates the pending attempt, session and expected issuer before exchange. The code is for the token endpoint, not the photo API.
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. View full-size illustration (opens in a new tab)

Handling the code

The code is short-lived and single-use. It is associated with the client and redirect URI, and in this flow with the PKCE challenge. The printer should treat its contents as opaque: it presents the code to the token endpoint rather than trying to decode an account identifier or permissions from it.

Codes still need protection. A callback URL can accidentally end up in analytics, request logs, browser history, or referrer information. Keep the callback focused on processing the response, avoid third-party resources there, and move the browser to a clean application URL after handling it. Do not record the full callback query in application logs.

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.

Try it in the Lab

PUT IT INTO PRACTICE

Check your understanding

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

0 of 2 answered correctly

Enable JavaScript to answer these questions and save progress in this browser.

QUESTION 1 OF 2The 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?

QUESTION 2 OF 2Why should the printer avoid logging the entire callback URL?

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