TL;DR
- Open Authorization lets an app act on your account at another service with a token, never with your password, and each flow is a different way to get that token.
- Apps with a user and a browser should use the authorization code flow with Proof Key for Code Exchange, the default for web, mobile and desktop apps.
- Devices without a browser use the device code flow, which attackers can abuse for phishing, while background jobs use client credentials.
- The implicit flow is no longer recommended. Pick the flow by who is present and read the permissions before you approve.
OAuth 2.0 (Open Authorization) is the reason a photo editor can read your cloud storage without ever seeing your password. It is also a framework with several ways in, called flows or grant types, and picking the wrong one is how most OAuth mistakes start. This is a reference built from the IETF specifications listed in the sources, not a lab write-up.
What OAuth does#
OAuth gives an application limited access to an account at another service. The user stays in control: they sign in at the service itself, see what the app asks for and approve or refuse. The app receives an access token instead of a password.
Think of a valet key. You hand the valet a key that starts the car and nothing else: no trunk, no glovebox, no house keys. An access token works the same way. It carries specific permissions (called scopes, such as “read photos”), it expires, and you can cancel it without changing your password.
Four roles appear in every flow. The user owns the data. The client is the app that wants it. The authorization server signs the user in and issues tokens. The resource server, usually an API, accepts the token and returns the data.
The authorization code flow with PKCE#
This is the flow to reach for when a user is present and the app can open a browser, which covers web apps, mobile apps, desktop apps and single-page apps. Take “Sign in with Google” on a new site:
The code travels through the browser, which is the exposed part. PKCE (specified in RFC 7636, a document of the Internet Engineering Task Force) makes a stolen code useless: whoever intercepts it does not have the secret that matches the challenge. The security best practice (RFC 9700) now asks for PKCE with every public client, and recommends it for the rest.
If you later want to revoke access, you remove the app in your Google account settings. Your password stays as it is.
The device code flow for devices without a browser#
A smart television, a command-line tool or a headless server has no comfortable way to show a sign-in page. In the device code flow (RFC 8628) the device asks the authorization server for a code and shows it to you with a short address. You open that address on your phone or laptop, sign in, type the code and approve. Meanwhile the device polls the server until a token is ready.
It works well, and it has a known weakness: the person who types the code may not be the person who started the request. That is the basis of device code phishing, where an attacker starts the flow and talks a victim into approving it. I covered the risks and mitigations for AI agents separately. Use this flow only where a browser really is missing.
The client credentials flow for apps without a user#
Some software acts for itself: a nightly job that updates a database, a service calling another service. There is no user and no consent screen. The app authenticates with its own credentials, a client ID and a secret or a certificate, and gets an access token for its own permissions.
The weak point is the secret. It has to live somewhere, and whoever copies it is the app. Where a cloud platform can issue the identity instead, I prefer that; my lab on a secretless agent with a managed identity shows the app-only token this flow produces, with no secret stored.
The implicit flow and why to skip it#
The implicit flow was designed for browser apps that could not keep a secret. It returned the access token directly in the browser address, with no code exchange. That puts the token in browser history, logs and referrer headers, and there is no way to bind it to the app that asked for it.
The best practice document says it should not be used, and the authorization code flow with PKCE replaces it for single-page apps. The same document also forbids the resource owner password grant, where the app collects your username and password itself. That is the exact situation OAuth was invented to end.
The flows side by side#
| Flow | Who is present | Typical app | Status |
|---|---|---|---|
| Authorization code with PKCE | A user with a browser | Web, mobile, desktop and single-page apps | The default choice |
| Device code | A user on a second device | Televisions, command-line tools, headless servers | Fine, with phishing awareness |
| Client credentials | Nobody | Background jobs, service to service | Fine, protect the secret |
| Implicit | A user with a browser | Old single-page apps | Do not use |
The tokens you will meet#
- Access token. The valet key. The resource server checks it on every call. It is short-lived, and it can be stolen like any bearer token; binding it to a key with DPoP is one way to make a stolen copy worthless.
- Refresh token. A longer-lived credential that gets a new access token without asking you to sign in again. Treat it like a password.
- ID token. Part of OpenID Connect (OIDC), the sign-in layer on top of OAuth. It is a signed token, usually a JWT (a JSON (JavaScript Object Notation) Web Token), that tells the app who signed in. It proves identity, it is not for calling APIs.
Two related topics deserve their own articles. When one service needs to pass a user’s access on to another, that is token exchange, with delegation and impersonation. And when a MCP server fronts an API, my lab on refusing token passthrough shows why it exchanges a user’s token instead of forwarding it.
What to check before you click Allow#
My view, labelled as opinion: the consent screen is the only security control the user sees, and it is read too rarely. Look at who is asking and at what, not only at the name of the app. “Read your calendar” and “read, create and delete everything in your account” are very different tokens.
Three habits help. Approve the smallest set of permissions that makes the app work. Check the address you are signing in at before you type anything. And revisit the list of connected apps in your account now and then, because every forgotten grant is a token that can still be used.
Sources#
This post as Markdown · RSS · JSON feed
New posts by email
One email a week with new posts and labs. Unsubscribe anytime.
Your address is stored with Kit, which sends the emails. Details