Beta

Create a tenant

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

Why use the authorization code flow?

Connecting the printer to Ava's photos takes several messages, and some of them have to pass through her browser. The authorization code flow sends only a short-lived code along that route and delivers the access token in a direct request the browser never sees.

Carrying the result back

Ava has chosen a photo book in the printing application. The next step is to choose photos from her photo account, so she selects Connect photo account.

That button starts several conversations. Ava's browser visits the photo service, the photo service sends a result back to the printer, and the printer asks for the credential it will use at the photo API. The authorization code flow decides which of those messages travel through the browser and which do not, and following who sends each one explains why OAuth uses more than one endpoint.

The printer needs an access token, and only Ava can approve one, at the photo service. Her approval happens in her browser, on the photo service's own pages, as Grants, scopes, and consent described. Its result then has to travel back to the printer, and the only route from those pages to the printer runs through her browser: the photo service redirects the browser to the printer's redirect URI, one of the endpoints introduced in Roles and endpoints, and puts the result in that URL.

A browser is a poor place to carry a token, and a URL is a poor place to put one.

How addresses leak

Imagine the photo service sent the access token itself in the redirect, so Ava's browser opened an address like this:

https://printer.example/oauth/callback?access_token=demo-access-token-7

That address does not stay in one place. Several ordinary features of the web copy it.

  • Browser history. The browser saves every address it visits. Anyone who later uses the same computer can find it, and many browsers sync history to other devices and to the browser maker's account service.
  • Server logs. Web servers usually record the full address of every request they receive, query included. The printer's logs, and those of any proxy or load balancer in front of it, are kept for weeks or months, read by staff, and copied into monitoring tools that were never designed to hold credentials.
  • The Referer header. When the printer's callback page loads an image, a script or a font from another site, or Ava follows a link from it, the browser can send that site the page's address in Referer, as What browsers add showed. Many browsers now trim it to the site name by default, but a page can ask for more, and a client cannot rely on every browser and setting.
  • Shared links. People copy addresses from the address bar to share a page, report a problem or paste into a support ticket, and screenshots capture the address bar along with everything else.

Any of those copies would put the token in someone else's hands, and a bearer token works for whoever holds it. Nothing in a URL ties the token to the application that asked for it.

Splitting the delivery

The authorization code flow splits delivery into two messages. The browser carries back only an authorization code to the printer's redirect URI. The code is the intermediate credential Roles and endpoints described: the photo API does not accept it, it works once, and it expires within minutes. The printer then sends that code straight to the photo service's token endpoint, in a request of its own, and the tokens arrive in the response to that request rather than in any address.

How applications communicate named these two routes. The redirect travels the front channel, through the browser, where addresses get copied. The token request travels the back channel, directly from the printer to the photo service. The back channel also gives the photo service something a redirect cannot: a chance to check who is asking before it hands over a token. The printer proves it started this attempt with the one-time PKCE verifier from Public and confidential clients, and as a confidential client it also authenticates with its own credentials. A code copied from a log or a shared link arrives with neither.

The address holds an access token

Callback address
?access_token=...
Photo API, given a copy
Accepts it
To use a copy
Nothing more
Token arrives
In the address

A leaked copy works for whoever holds it

The address holds an authorization code

Callback address
?code=...
Photo API, given a copy
Refuses it
To use a copy
Verifier and client authentication
Token arrives
In a direct response

Works once and expires within minutes

A code copied from a log or a shared link arrives with neither.

The same leaked callback address, with a token in it and with a code in it. The code is refused by the photo API and cannot be redeemed without the printer's verifier and credentials.

Where the token response ends up depends on the deployment. A server application such as the printer receives it on its backend and can keep the token out of the browser altogether. A public browser application has no backend, so it receives the response in JavaScript and still needs protection against injected scripts. A code flow with PKCE does not make browser token storage disappear. It keeps bearer tokens out of the authorization redirect and binds redemption of the code to the attempt that started the request.

Preparing the connection

Now follow one connection from the start. Before Ava ever selects Connect, the printer has a client registration with the photo service. That registration includes a client ID and an allowed return address. In this fictional example, they are:

Client ID: photo-printer
Redirect URI: https://printer.example/oauth/callback

The printer also knows the photo service's authorization and token endpoints from trusted configuration. It does not discover where to send credentials by trusting an address supplied in a returning browser request.

When Ava selects Connect, the printer creates a pending transaction: a record tied to her current session that holds what the printer needs to finish this particular attempt. It holds two fresh random values. One, called state, travels out with the request and must come back unchanged, so the printer can recognize the response as the answer to this attempt. The other is the PKCE verifier, which never leaves the printer until it redeems the code. Proof Key for Code Exchange (PKCE) and Correlating requests and responses examine each value in detail.

Visiting the photo service

The printer directs Ava's browser to the photo service's authorization endpoint. Its request identifies the printer, asks for permission to read photos, and names the registered return address. Everything in it is visible in the address bar, so it carries nothing secret, and the verifier stays behind in the pending transaction.

The photo service checks the request and establishes which photo account is involved. Ava might need to sign in, or she might already have a session there. The photo service then decides whether to authorize the requested access, and depending on earlier approval and its policy, Ava may see a consent screen. If she types a password, she types it on the photo service's own page, never the printer's.

When the request succeeds, the photo service redirects Ava's browser back to the printer's callback with the authorization code. This is the one moment in the flow when a credential sits in an address, which is why the code is designed to be worth so little there.

Finishing the exchange

The callback carries the code, the state value, and an iss parameter naming the issuer, the authorization server that answered. The printer first checks that state matches the pending attempt for Ava's session and that iss names the photo service it sent her to. It claims that attempt once, so a second copy of the same callback finds nothing to finish, and it moves her browser on to a clean address so the code does not stay in the address bar. Only then does its backend send the code to the token endpoint, together with the PKCE verifier and the client authentication its registration requires.

If those checks succeed, the token endpoint returns an access token to the backend. The backend uses that token when requesting photos from the API, and the API still decides whether each operation is permitted.

The browser carries the authorization request and the returning code. The printer backend checks the response, exchanges the code, and uses the access token to request photos.

The browser carried the code. The access token travelled only in the direct exchange between the backend and the token endpoint, and from there to the API, and the backend keeps it out of browser-facing responses.

The printer can now retrieve the photos Ava authorized. It has not received her photo account's password, and this OAuth exchange alone has not established a standardized sign-in result for a printer account. OpenID Connect addresses that separate requirement.

Check your understanding

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

A public browser client uses the authorization code flow with PKCE. Where does its token response arrive? 1 of 3

Choose one answer.

Ava's browser has just returned to the printer's callback with an authorization code. What should happen next? 2 of 3

Choose one answer.

The printer finishes Ava's connection, then the same callback address, code included, reaches it a second time. What should the printer do with the second copy? 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