Skip to main content
Version: 1.12.0

Class: CantonCachingTokenSource

Defined in: canton/authentication/token-source.ts:128

A TokenSource that caches a token and lazily re-fetches via a caller-supplied fetcher when the cached token is expired or missing.

Mirrors the caching behaviour of golang.org/x/oauth2 reusable token sources: 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

Constructors

Constructor

new CantonCachingTokenSource(fetcher: () => Promise<AccessToken>, initial?: AccessToken): CachingTokenSource

Defined in: canton/authentication/token-source.ts:140

Creates a new caching token source.

Parameters

ParameterTypeDescription
fetcher() => Promise<AccessToken>Called when the cached token is missing or expired. MUST return a fresh AccessToken.
initial?AccessTokenOptional initial token (skips the first fetch).

Returns

CachingTokenSource

Methods

getCachedToken()

getCachedToken(): AccessToken | undefined

Defined in: canton/authentication/token-source.ts:171

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:146

Returns a valid token, fetching if the cached one is expired or missing.

Returns

Promise<AccessToken>

Implementation of

CantonTokenSource.token