Choosing a flow
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. grant answers a particular situation. A few questions about whose access it is, how the person can approve it and whether it must continue usually point to one flow, and the older flows that skip those questions are best left alone.
Asking about the situation
Over the last few lessons, the printing application has obtained access in several different ways. It sent Ava's browser to the photo service to read her photos, kept a refresh token for next December's calendar, and authenticated as itself to submit print jobs. A photo frame polled for a token while Ava approved it on her phone, and Lantern's portal presented an assertion from its own identity providerA service that authenticates users and tells other applications about the sign-in, so those applications never handle the users' passwords. In OpenID Connect it is called an OpenID Provider..
Each of those choices followed from the situation, not from a preference for one flow. A few questions about the situation usually lead to the right one.
Whose access is it? Start here, because it separates the grants most clearly. If the client needs access to something that belongs to a person, such as Ava's photos, a person has to authorize it. If the client needs access as itself, as the printer does at the print lab, there is no person to involve, and the client credentials grant fits. Ava can't approve the printer's dealings with the print lab, and nobody needs her to.
Can the person use a browser on this device? When a person authorizes access, the authorization code flowThe main OAuth flow: the browser visits the authorization server, where the person signs in and approves access, then carries an authorization code back to the client, which exchanges it for tokens directly. When the client runs on a server, the tokens never pass through the browser. with 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. is the default. The person signs in and decides at 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., and the result returns to the client that asked. If the device cannot reasonably show a browser or accept typing, like the photo frame, the device 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. grant moves the sign-in and approval to another device.
Has the person's authority already been established elsewhere? Sometimes an organization has authenticated the person and has an arrangement with the authorization server about what that means, as Lantern did. Then an assertion grant can turn the organization's signed statement into 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. without another interactive approval. Without that arrangement, the person authorizes through one of the interactive flows.
Does the access need to continue? This question is separate from the others. A refresh tokenA longer-lived credential that a client sends to the authorization server, never to an API, to get new access tokens without asking the person again. is not a way to obtain access for the first time. It extends an authorization the client already has, obtained through one of the flows above, so the client can get new access tokens when the person is not present.
Where does the client run? This does not usually change the grant, but it changes how the client uses it. A confidential clientAn OAuth client, typically running on a backend, that can keep a credential such as a client secret or private key protected, and so can authenticate itself to the authorization server. authenticates 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.. A public clientAn OAuth client, such as code running in a browser or an app on a phone, that cannot keep a credential secret because the people using it can inspect it. It relies on protections such as PKCE instead of a client secret. cannot, so it relies on protections such as PKCE, and it cannot use the client credentials grant at all. An application running in the browser may be better served by a backend that acts as its confidential client. The Application architectures lessons, starting with Server-rendered web applications, look at those designs one at a time.
Situations side by side
Each row of this table pairs a situation with the grant that fits it. The first five are the grants this series has covered; the last two are later extensions for situations the others don't handle well.
| Situation | Flow or grant |
|---|---|
| A person authorizes access in a browser on the same device | Authorization code flow with PKCE |
| A person authorizes access for a device with no practical browser or keyboard | Device authorization grant |
| A client accesses a service as itself, with no person involved | Client credentials grant |
| A trusted issuer has already vouched for the person, under an arrangement set up in advance | JWT or SAML assertion grant |
| A client needs new access tokens for an authorization it already holds | Refresh token grant |
| The client starts the request, and a known person approves it on their own phone, with no code to type | Client-Initiated Backchannel Authentication (CIBA), from OpenID Connect |
| A service that received a token for a person needs a token for another service, still on that person's behalf | Token exchange |
Real products often combine rows. The printer uses the 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. flow to connect Ava's account, the refresh token grant to keep the connection working, and client credentials for its own dealings with the print lab. Each piece is chosen for the access it provides.
The last two rows go beyond the grants in this series. A print shop kiosk that knows Ava and asks the photo service to send an approval request straight to her phone, without a code to type, uses CIBA, which Separating the consumption and authentication devices introduces. A photo API that must fetch Ava's image files from a separate storage service, still on her behalf, uses token exchange, which The problem token exchange solves introduces.
Flows to avoid
You'll still meet two older grants in existing integrations and older tutorials.
The implicit grant returned an access token directly in the browser redirect, with no code exchange. It was designed for browser applications at a time when they had few alternatives. Tokens placed in redirect addresses can leak through browser history, server logs and the Referer header a browser sends to the next site, and nothing binds them to the client that asked. Browser applications now use the authorization code flow with PKCE instead.
The resource owner password credentials grant let a client collect a person's username and password and send them to the token endpoint. That is the password sharing OAuth set out to replace. It also prevents the authorization server from using stronger sign-in methods, because the client only knows how to handle a password. Current security guidance says it must not be used.
Neither should be chosen for a new integration. In History, legacy, and migration, The implicit grant and The password grant explain how they worked, and Migrating older integrations how to move existing integrations away from them.
Choosing a grant is only the first decision. Whichever flow a client uses, the authorization server checks each request against the client's registration, and a confidential client also proves who it is.
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
- Prove each client can use only the grant that fitsClassify every lab client by whose access it needs and where it runs, then confirm with real refusals that registration and Flow Policy hold each one to its grant.