Access Token vs Refresh Token
Definition
A dual-token authentication architecture designed to maximize security while maintaining a seamless user experience.
Explain Like I'm New
JWTs cannot be easily revoked. If a hacker steals your JWT, they own your account until the token expires. To fix this, we use TWO tokens. 1. The Access Token: Lives for only 15 minutes. It is used for all API requests. If stolen, the hacker only has 15 minutes. 2. The Refresh Token: Lives for 30 days, saved securely in an `httpOnly` cookie. It can only do ONE thing: ask the server for a new 15-minute Access Token.
Real World Example
You log into Spotify. You never have to log in again. Spotify gives you a 15-minute access token and a 30-day refresh token. Every 15 minutes in the background, the app silently uses the refresh token to get a new access token without interrupting your music.
Common Use Cases
- •High-security enterprise apps
- •Seamless mobile app logins
Terminal Output
Interview Questions
basic
- Why not just make the Access Token last for 30 days?
intermediate
- Where is the safest place to store a Refresh Token in a web browser?
advanced
- What is Refresh Token Rotation?