Skip to main content
Version: 1.13.1

Class: CantonAuthorizationCodeProvider

Defined in: canton/authentication/authorization-code.ts:393

An AuthProvider backed by caller-supplied token-fetch and token-refresh callbacks.

The embedder implements the interactive flow (browser + callback) using buildAuthorizationRequest, validateAuthorizationCallback, and exchangeAuthorizationCode, then wraps the resulting token in this provider. Refresh uses refreshAuthorizationCodeToken when a refresh token is available; otherwise the initial token is re-fetched via the fetchToken callback.

This keeps the SDK runtime-agnostic: no callback server or browser logic lives here, only the caching/refresh plumbing an embedder would otherwise have to re-implement.

Implements

Constructors

Constructor

new CantonAuthorizationCodeProvider(config: AuthorizationCodeAuthConfig, initialToken: AccessToken, fetchToken: () => Promise<AccessToken>, options?: OAuthRequestOptions): AuthorizationCodeProvider

Defined in: canton/authentication/authorization-code.ts:408

Creates a provider from an initial token and callbacks.

Parameters

ParameterTypeDescription
configAuthorizationCodeAuthConfigAuthorization code config (used for refresh).
initialTokenAccessTokenThe token obtained from exchangeAuthorizationCode.
fetchToken() => Promise<AccessToken>Called when the cached token is expired and no refresh callback is supplied (or refresh fails). Must return a fresh token.
options?OAuthRequestOptionsOptional fetch override and abort signal (threaded to refresh).

Returns

AuthorizationCodeProvider

Properties

type

readonly type: "authorizationCode"

Defined in: canton/authentication/authorization-code.ts:394

The auth scheme this provider was built from.

Implementation of

CantonAuthProvider.type

Methods

getCachedToken()

getCachedToken(): AccessToken | undefined

Defined in: canton/authentication/authorization-code.ts:425

Returns the currently cached token (possibly expired) without fetching.

Returns

AccessToken | undefined


token()

token(): Promise<AccessToken>

Defined in: canton/authentication/authorization-code.ts:420

Returns a valid access token, refreshing or re-fetching as needed.

Returns

Promise<AccessToken>

Implementation of

CantonAuthProvider.token