Refresh Token Service
Refresh tokens, explained simply:
Think of a refresh token as a long-lived “session receipt” stored in an HttpOnly cookie.
Every time you use it, we swap it for a brand new one (so an old one can’t be reused).
If an old token shows up again, we assume it was stolen and shut down the whole session family.
This in-memory implementation is perfect for dev/single-node. Use Redis/DB for production.
Key ideas:
Each refresh token belongs to a family (one login session) and is bound to a DPoP key thumbprint (jkt).
Rotate-on-use and reuse detection keep sessions safe.
Types
Info needed to set the refresh cookie on the response. id goes into the cookie value; expiresAt is used to compute Max-Age; familyId groups a session.
Result of trying to use a refresh token.
Functions
Start a new session: create a fresh refresh token record bound to the user (and DPoP key if present).
Revoke a session family by presenting one of its token ids. Handy for logout when we read the cookie value.
Revoke every refresh token in a session family. Use this when we detect reuse or other anomalies.
Use-then-rotate flow for refresh tokens.