.NET › Authentication & Authorization (Identity, JWT, OAuth)
How do refresh tokens work alongside short-lived access tokens, and why is this pattern used?
IntermediateAnswer
Access tokens are intentionally short-lived (minutes to a couple hours) to limit the damage if one is stolen, while a longer-lived refresh token (stored more securely, often HttpOnly cookie) can be exchanged for a new access token without requiring the user to re-authenticate with credentials again, balancing security (short exposure window) with usability (infrequent re-logins).
// Client uses access token normally until it expires
// Then exchanges the refresh token for a new pair:
POST /auth/refresh
{ "refreshToken": "long-lived-opaque-token" }
// Response:
{ "accessToken": "new-short-lived-jwt", "refreshToken": "new-refresh-token" }Real-world example A mobile banking app uses 15-minute access tokens with a 30-day refresh token stored in secure device storage, so users stay logged in for a month without needing to constantly re-enter credentials, while limiting a stolen access token's usefulness to a short window.