Class: CantonCachingTokenSource
Defined in: canton/authentication/token-source.ts:126
A TokenSource that caches a token and lazily re-fetches via a
caller-supplied fetcher when the cached token is expired or missing.
The first token() call fetches; subsequent calls return the cached value
until it expires, at which point a new fetch is triggered. Concurrent callers
share a single in-flight fetch promise to avoid duplicate token requests.
Implements
TokenSource
Constructors
Constructor
new CantonCachingTokenSource(
fetcher: () =>Promise<AccessToken>,initial?:AccessToken):CachingTokenSource
Defined in: canton/authentication/token-source.ts:138
Creates a new caching token source.
Parameters
| Parameter | Type | Description |
|---|---|---|
fetcher | () => Promise<AccessToken> | Called when the cached token is missing or expired. MUST return a fresh AccessToken. |
initial? | AccessToken | Optional initial token (skips the first fetch). |
Returns
CachingTokenSource
Methods
getCachedToken()
getCachedToken():
AccessToken|undefined
Defined in: canton/authentication/token-source.ts:169
Returns the currently cached token (possibly expired) without triggering a fetch.
Used by refresh callbacks that need to inspect the old token's refreshToken
field without recursively calling token (which would deadlock when
the refresh callback is itself the fetcher).
Returns
AccessToken | undefined
token()
token():
Promise<AccessToken>
Defined in: canton/authentication/token-source.ts:144
Returns a valid token, fetching if the cached one is expired or missing.
Returns
Promise<AccessToken>
Implementation of
TokenSource.token