iamops.dev Search
Argo on X RSS feed
ENEnglish

Knowledge Explainer · 5 min Beginner

For newcomers and managers who need to know which sign-in flow fits which kind of app.

OAuth 2.0 flows explained: which one fits which app

OAuth 2.0 in four flows: authorization code with PKCE, device code, client credentials and the retired implicit flow. Which one to use, and why.

Four steps of the authorization code flow with PKCE: the app sends the user to the authorization server, the user signs in and approves, the app receives a short-lived code, and swaps it for a token.
TL;DROpen Authorization lets an app act on your account at another service…

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:

Sequence: the app redirects the user to the authorization server with a PKCE challenge, the user signs in and approves, the server redirects back with a short-lived code, and the app swaps the code and verifier for an access token.
Authorization code with PKCE. The app only ever holds a short-lived code until it proves itself with its PKCE secret.

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.

Four steps of the authorization code flow with PKCE: the app sends the user to the authorization server, the user signs in and approves, the app receives a short-lived code, and swaps it for a token.
The password never reaches the app. The user signs in at the authorization server, and the app trades a short-lived code plus its PKCE secret for a token.

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.

Sequence: the device requests a device code, shows a short user code and address, the user signs in on a second device and enters the code, and the device polls until it receives an access token.
Device code. The device waits while the person approves on a second device.

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#

Discuss this on X or LinkedIn

Follow on X

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

Related research and labs

Type to search every page. Use the arrow keys to move through the results.

    Open the full search page