Repository navigation
feat(auth): issue rotating refresh tokens (SHD-1084) - #35
Merged
Merged
Conversation
Signed-off-by: janosmurai <janos.murai@axem.dev>
janosmurai
force-pushed
the
SHD-1084/refresh-tokens
branch
from
October 19, 2026 12:29
e0dd660 to
87d5f36
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of change
Related issue
Closes SHD-1084
Description
/v1/loginreturned only a one-hour access token, so clients that need a session longer than an hour kept the user's password and logged in again. This PR adds rotating refresh tokens, so clients can drop the password.API
POST /v1/loginnow also returnsrefresh_tokenandrefresh_token_expires_in. The change is additive.POST /v1/token/refreshwith{"refresh_token": ...}returns a new access token and a new refresh token, in the sameAccessTokenResponseshape. The token that was sent is invalidated.POST /v1/logoutwith the same body revokes the session. It always answers204, so it doesn't reveal which tokens exist.Security model
aws-lc-rsSystemRandom). Only its SHA-256 digest is stored. That's enough at this entropy, and it keeps refreshing cheap compared to Argon2.family_id. Presenting a token that was already rotated means it was copied, so the whole family is revoked, including the legitimate successor.REFRESH_TOKEN_REUSE_GRACE), presenting the old token just gets a401, without revoking. This covers two tabs or requests refreshing at the same time. Rotation is a conditionalUPDATE ... WHERE used_at IS NULLplus the successorINSERT, in one transaction, so only one concurrent refresh can succeed.refresh_tokens.user_idusesON DELETE CASCADE, so deleting a user also deletes their sessions.Validation
cargo fmt --checkcargo clippy --all-targets --all-features -- -D warningscargo build --verbose --all-featurescargo test --verbose --all-featuresAdditional validation details:
just check: 170 tests passed.shaide-dbtests: rotation stores the successor in the same family, a token rotates only once, revoking a family doesn't affect other families, and cleanup deletes only expired rows.routes::users::tests):.sqlxoffline data regenerated withcargo sqlx prepare --workspace: 6 new query files, existing ones unchanged.Deployment and compatibility
shaide-clideserializesAccessTokenResponse, so it needs a server with this change. Both ship from this repo.JWT_SECRET, so rotating the JWT secret logs users out of their access tokens but not their sessions.Documentation
The README's Authentication section now covers refresh, rotation, reuse detection and logout. The new endpoints are in the OpenAPI spec.
Checklist
Signed-off-bytrailer (git commit -s).Additional information
revoke_refresh_token_familyfor each of the user's families, or delete the user's rows.AI assistance: