All posts
Internet Fundamentals

OAuth and OpenID Connect: Which Token Is Which, and the Flow to Use

By

October 26, 2026

6 min read

"Sign in with Google" is OpenID Connect; "let this app read my calendar" is OAuth. Access tokens, refresh tokens and ID tokens do different jobs, and mixing them up causes most auth bugs. The authorization code flow with PKCE, what each token is for, and the mistakes we see in fast-built apps.

Internet Fundamentals
OAuth
OpenID Connect
Authentication
Security

OAuth 2.0 (RFC 6749) lets an app act on a user's behalf at another service without seeing their password. OpenID Connect is a layer on top that also tells the app who the user is. Most "Sign in with..." buttons are OpenID Connect.

The three tokens

Token

For

Who reads it

Typical lifetime

ID token

Proving who signed in, to your app

Your app, once, at sign-in

Minutes

Access token

Calling an API

The API it was issued for

Minutes to an hour

Refresh token

Getting new access tokens without signing in again

Only the authorization server

Days to months; rotate it on each use

Want a second opinion on this for your system?

Book a free 30-minute call. You'll leave knowing what we'd do first and roughly what it costs, whether or not you hire us.

The flow to use: authorization code with PKCE

  1. Your app creates a random secret (the code verifier) and sends a hash of it (the code challenge) when redirecting the user to sign in.

  2. The user signs in at the provider, which redirects back with a short-lived authorization code.

  3. Your app exchanges the code, plus the original verifier, for tokens. An attacker who intercepts the code cannot use it without the verifier.

PKCE (RFC 7636) was designed for mobile apps and is now recommended for every client, including server-side web apps. The older implicit flow, which returned tokens in the URL, should not be used; the OAuth 2.1 work removes it.

Mistakes we see

  • Sending the ID token to your API as if it were an access token. APIs should accept access tokens issued for them, and check the audience.

  • Not validating tokens: check the signature, issuer, audience and expiry on every request, using the provider's published keys.

  • Long-lived access tokens because refresh "was annoying". A leaked token then works for weeks.

  • Refresh tokens in localStorage in a browser app. Keep them server-side or in an HttpOnly cookie, and rotate them.

  • Redirect URIs with wildcards, which let an attacker receive the authorization code. Register exact URIs.

hoolco Monthly Review

Once a month: what changed in tech that month and what it means for you, from cloud and AI to security and the tools you build with. Every item links to its source. No sales pitch, unsubscribe in one click.

As of October 26, 2026. Provided as is, for general information, and accurate to the best of our knowledge on the date shown. Not legal, compliance, tax, financial or other professional advice. Prices, limits and vendor services change; check current vendor documentation before relying on anything here. Terms of use.