Q16: How can you revoke stateless JWT access tokens before their natural expiration?
Because JWTs are stateless, instant token revocation requires adding specific tracking mechanisms:
- Short Lifespans + Refresh Tokens: Keep access token lifespans extremely short (e.g., 5 minutes); revoke access by invalidating the refresh token on the Auth Server.
- Token Denylist / Blacklist in Redis: Store revoked JWT
jti(JWT ID) claims in an in-memory Redis cache with TTL equal to the remaining expiration time. APIs check Redis during request processing. - User Token Versioning: Store an integer
token_versionon the User database record and inside the JWT payload. Incrementing the databasetoken_versionimmediately invalidates all active tokens for that user.
Key Takeaways
Keep JWT lifespans short to minimize the window of compromise.
Use Redis
jtiblacklists ortoken_versioncounters for instant multi-device logout enforcement.