Refresh Token Revocation
What you'll learn: How to invalidate refresh tokens server-side to securely end user sessions during logout or security incidents.
The Core Problem
You've implemented silent token refresh (from lesson 1607), but there's a critical gap: if a user clicks "logout" or you detect suspicious activity, simply deleting tokens from the client isn't enough. A stolen refresh token could still be used to generate new access tokens indefinitely. You need a server-side kill switch.
How Revocation Works
Refresh token revocation means maintaining a server-side record of which refresh tokens are still valid, then actively invalidating them when needed.
Think of it like a library card: When you lose your card, the library doesn't just hope you throw it away—they mark it as "canceled" in their system so it can't check out books anymore.
Common implementation strategies:
-
Allowlist approach: Store valid refresh tokens in a database with user ID and expiration. On refresh, check if the token exists and is not revoked.
-
Blocklist approach: Store only revoked token IDs. During refresh, reject any token on this list.
-
Token family tracking: Store token chains (from rotation in lesson 1611) and revoke entire families when compromise is detected.
When to Revoke
- User logout: Immediately revoke the user's refresh token(s)
- "Log out all devices": Revoke all refresh tokens for that user
- Security breach: Bulk revoke tokens for affected accounts
- Failed refresh with rotation: Revoke token family on reuse detection (lesson 1612)
The revocation happens server-side in your refresh endpoint—before issuing new tokens, verify the current refresh token hasn't been revoked.
Key Takeaway: Refresh token revocation provides server-side control over user sessions by maintaining a database record of valid or invalid tokens, ensuring logout and security actions truly end access even if tokens are stolen.