Repository navigation
feat(auth): add SDK token refresh strategy with fallback (#1321) - #1371
Merged
Kingsman-99 merged 2 commits intoNov 23, 2026
Merged
Kingsman-99 merged 2 commits into
Kingsman-99 merged 2 commits into
Conversation
|
@Phantomcall Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
6 tasks
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.
Implement SDK token refresh strategy (#1321)
Summary
Adds
TokenRefreshManager, a reusable authentication-token lifecycle manager. It refreshes JWTs shortly beforeexpiry, retries with exponential backoff, supports a fallback token source, coalesces concurrent callers, and reports
refresh activity through bounded tracking — without ever exposing tokens in logs or events.
What changed
src/tokenRefresh.tsdecodeTokenExpiry()reads theexpclaim of a JWT (base64url safe) without verifying the signature; opaque tokens are handled by refreshing proactively.setToken()installs a token and arms a preemptive timer based onrefreshBufferMs(default 60 s), so refreshes happen before expiry rather than after a failure.getToken()returns the cached token when valid, triggers a refresh when expiring/expired, and queues concurrent callers into one refresh cycle (queuedcounter).refresh()performs up tomaxRetriesattempts with exponential backoff and optional jitter, emits typed failure events, and supports a static or asyncfallbackTokensupplier when all attempts fail.fetchand clock, andexpiresInbased expiry.onRefreshed()/onRefreshFailed()subscriptions return unsubscribe functions;stats(),refreshedEvents()andfailedEvents()expose bounded, secret-free tracking.dispose()clears timers, aborts in-flight requests viaAbortController, rejects queued callers and cancels pending refreshes.src/index.tsfor the manager, error, helper and public types.test/tokenRefresh.test.ts(9 tests) cover expiry decoding, preemptive refresh, scheduled refresh, retry/backoff tracking, fallback, typed failure, concurrency coalescing, bounded tracking and disposal.Acceptance criteria addressed
TokenRefreshErroris thrown when none is configured.Testing
Note:
npm run lintwas already failing before this change due to pre-existing syntax errors/merge-conflict markers in unrelated repository files; no new TypeScript errors are introduced here.Backwards compatibility
Additive only; no existing module or API is modified.
closes #1321