Course contentsShow
← Computer Science
Lesson 2539 of 2,87256. Authentication and AuthorizationFree lesson

OAuth 2.0 Tokens: Access Tokens and Refresh Tokens

Distinguish between short-lived access tokens for API calls and long-lived refresh tokens for obtaining new access tokens.

OAuth 2.0 Tokens: Access Tokens and Refresh Tokens

What you'll learn: You'll understand the critical difference between short-lived access tokens used for API calls and long-lived refresh tokens used to obtain new access tokens.

The Two-Token System

OAuth 2.0 uses two distinct types of tokens to balance security and convenience:

Access tokens are short-lived credentials (typically lasting minutes to hours) that clients present when making API requests to protected resources. Think of an access token like a temporary hall pass—it grants you permission to access specific resources, but expires quickly. Because these tokens are frequently transmitted over networks and stored in memory, their short lifespan limits damage if they're intercepted or stolen.

Refresh tokens are long-lived credentials (days to months) used exclusively to request new access tokens from the authorization server. They're like a library card that lets you check out new hall passes when the old ones expire. Refresh tokens are never sent to resource servers—only to the authorization server—reducing their exposure to potential attackers.

Why This Split Matters

This two-token architecture provides defense in depth. If an access token leaks, an attacker has limited time to abuse it before it expires. The refresh token stays safely stored and isn't exposed during routine API calls. When the access token expires, the client uses the refresh token (over a secure channel) to silently obtain a fresh access token without requiring the user to log in again.

If a refresh token is compromised, the authorization server can revoke it, immediately cutting off the attacker's ability to generate new access tokens.

Key Takeaway: Access tokens are short-lived credentials for API requests, while refresh tokens are long-lived credentials used only to obtain new access tokens—together they minimize exposure while maintaining a seamless user experience.