How Access and Refresh Tokens Work

Published: (February 28, 2026 at 02:46 PM EST)
3 min read
Source: Dev.to

Source: Dev.to

Cover image for How Access and Refresh Tokens Work

Simple login flow

How tokens are issued and used across servers

  1. You request “Login with Google”.
  2. The app redirects to the Authorization Server (Google), which authenticates you and returns an authorization code.
  3. The app exchanges that code for an access token (and a refresh token).
  4. The app uses the access token to call the Resource Server on your behalf.

The Authorization Server handles who you are; the Resource Server handles what you’re allowed to do.

The Access Token

Think of the access token as a daily pass. Every request to the Resource Server includes this token, and the server validates it before responding.

  • Short‑lived – typically minutes to a few hours.
  • Frequent exposure – travels with almost every request, so a short lifespan limits the damage if it’s intercepted.

A long‑lived access token would be a security nightmare because an attacker could use it for an extended period.

The Refresh Token

When the access token expires, the app silently uses the refresh token to obtain a new access token from the Authorization Server—no user interaction required.

  • Long‑lived – days, weeks, or even months.
  • Rarely transmitted – only sent to the Authorization Server, never to the Resource Server.
  • Purpose‑specific – used solely to get new access tokens.

This separation keeps the refresh token safer and makes it easier to revoke if needed.

Quick Comparison

Quick Comparison

AspectAccess TokenRefresh Token
LifetimeMinutes‑to‑hoursDays‑to‑months
ExposureSent with every API requestSent only to Authorization Server
PurposeAuthorize resource accessObtain new access tokens
RevocationUsually short‑lived, less impactCan be revoked centrally

Why Not Use a Single Token?

A single long‑lived token sent with every request would be a security disaster. If stolen, an attacker would have unrestricted access for a long time. Splitting responsibilities:

  • Access token – short‑lived, limits exposure risk.
  • Refresh token – long‑lived, rarely exposed, easy to revoke.

References & Further Reading

0 views
Back to Blog

Related posts

Read more »

Sprint

!Sprint: Express sin repetir códigohttps://dev-to-uploads.s3.amazonaws.com/uploads/articles/9mcbu1c3wuvlq0tiuup0.png Introduction Sprint: deja de repetir código...