Refresh Token Rotation
You'll learn how rotating refresh tokens on each use creates a security tripwire that detects token theft.
The Core Idea
Refresh token rotation means that every time a client uses a refresh token to get a new access token, the server invalidates the old refresh token and issues a brand new refresh token alongside the new access token. Each refresh token is single-use only.
Think of it like a one-time-use subway card: once you swipe it through the turnstile, it's void. If someone steals your card after you've used it, the thief's attempt to use it triggers an alarm because the system knows that card should already be spent.
How It Works
- Initial Login: Client receives an access token and refresh token
- Token Refresh: When the access token expires, client sends the refresh token to get a new pair
- Server Response: Issues new access token + new refresh token, marks the old refresh token as "used"
- Detection: If the old refresh token is used again, the server knows something is wrong—either:
- The legitimate user still has the old token (hasn't refreshed yet), OR
- An attacker is replaying a stolen token
When suspicious activity is detected, the server can invalidate the entire token family (all tokens from that original login session), forcing the user to re-authenticate.
Why It Matters
Without rotation, a stolen refresh token remains valid until expiration—potentially days or weeks. With rotation, the theft window shrinks to the time between refreshes, and theft becomes detectable rather than just preventable.
Key Takeaway: Refresh token rotation transforms long-lived refresh tokens into short-lived, single-use credentials that automatically detect replay attacks, significantly reducing the impact of token theft.