New v4.15.0 created automatically from CircleCI#147
Merged
Conversation
…or refresh tokens
Add reuseWindowMs and rotate options to DynamicApiRefreshTokenOptions.
- reuseWindowMs: grace window in ms — the superseded jti is accepted
within this period and returns the cached token pair, preventing
false-positive 401s on concurrent multi-tab / multi-device bursts.
- rotate: false — persistent-token mode; validates the stored hash on
each call without rotating it; server-side revocation via logout
still works.
- Atomic rotation via findOneAndUpdate (compare-and-swap on stored
raw value) — eliminates the race condition between concurrent
read-then-write operations; CAS misses fall back to the grace window.
- Changed storage format from plain bcrypt hash to JSON RefreshTokenRecord
({ currentHash, previousHash?, rotatedAt?, cachedTokens? });
backward-compatible with existing plain-hash values.
Unit tests: 86 passing, 98.93% branch coverage.
E2E tests: 14 passing (grace window burst, rotate=false multi-use,
revocation after rotate=false, grace window expiry).
…o ~6 Extract 4 private helpers to flatten the refreshToken method: - extractIncomingJti: decodes rawToken and returns the jti claim - handleInvalidCurrentJti: grace-window check + throw on invalid current jti - rotateCasOrThrow: atomic CAS rotation, delegates CAS miss to handleCasMiss - handleCasMiss: re-read + grace-window check after concurrent rotation All existing tests pass (97). New unit tests added for each helper. Coverage: 100% stmt/lines/fn on base-auth.service.ts.
|
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.



feat(auth): add grace window, rotate=false, and atomic CAS rotation for refresh tokens
Add reuseWindowMs and rotate options to DynamicApiRefreshTokenOptions.
within this period and returns the cached token pair, preventing
false-positive 401s on concurrent multi-tab / multi-device bursts.
each call without rotating it; server-side revocation via logout
still works.
raw value) — eliminates the race condition between concurrent
read-then-write operations; CAS misses fall back to the grace window.
({ currentHash, previousHash?, rotatedAt?, cachedTokens? });
backward-compatible with existing plain-hash values.
Unit tests: 86 passing, 98.93% branch coverage.
E2E tests: 14 passing (grace window burst, rotate=false multi-use,
revocation after rotate=false, grace window expiry).
refactor(auth): reduce cognitive complexity of refreshToken from 24 to ~6
Extract 4 private helpers to flatten the refreshToken method:
All existing tests pass (97). New unit tests added for each helper.
Coverage: 100% stmt/lines/fn on base-auth.service.ts.
chore(release): 4.15.0