Skip to main content
Version: 1.13.1

Function: validateCantonAuthorizationCallback()

validateCantonAuthorizationCallback(config: AuthorizationCodeAuthConfig, callbackUrl: string | URL, expectedState: string, options?: OAuthRequestOptions): Promise<ValidatedCallback>

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

Validate the authorization callback URL and extract the code + state.

Checks for an OAuth2 error redirect first (e.g. the user denied consent), then validates the state parameter (CSRF protection) and the presence of a code via oauth4webapi.validateAuthResponse.

Parameters

ParameterTypeDescription
configAuthorizationCodeAuthConfigAuthorization code config (with authUrl, clientId).
callbackUrlstring | URLThe full redirect URL the browser was sent back to (including ?code=…&state=… or ?error=…).
expectedStatestringThe state value from buildAuthorizationRequest.
options?OAuthRequestOptionsOptional fetch override and abort signal.

Returns

Promise<ValidatedCallback>

The validated ValidatedCallback (code + state).

Throws

CCIPError (CANTON_AUTH_ERROR) on an OAuth2 error redirect, state mismatch, or missing code.

Example

TypeScript
const { code } = await validateAuthorizationCallback(
config, 'http://localhost:8400/callback?code=abc&state=xyz', req.state,
)