Authorization interface

Provides user authorization, token exchange, and sign-in lifecycle operations.

Methods

exchangeToken(TurnContext, string, AuthorizationHandlerTokenOptions)

Exchanges the user token using an authorization handler.

exchangeToken(TurnContext, string[], string)

Exchanges the user token for the requested scopes.

exchangeTokenAsTokenCredential(TurnContext, string, AuthorizationHandlerTokenOptions)

Creates a credential that exchanges the current turn's user token.

getToken(TurnContext, string)

Gets the user token for an authorization handler.

getTokenAsTokenCredential(TurnContext, string)

Creates a credential backed by the current turn's user token.

onSignInFailure((context: TurnContext, state: TurnState, authHandlerId?: string, errorMessage?: string) => Promise<void>)

Registers a callback for failed sign-in.

onSignInSuccess((context: TurnContext, state: TurnState, authHandlerId?: string) => Promise<void>)

Registers a callback for successful sign-in.

signOut(TurnContext, TurnState, string)

Signs out the user from one or all authorization handlers.

Method Details

exchangeToken(TurnContext, string, AuthorizationHandlerTokenOptions)

Exchanges the user token using an authorization handler.

function exchangeToken(context: TurnContext, authHandlerId: string, options?: AuthorizationHandlerTokenOptions): Promise<TokenResponse>

Parameters

context
TurnContext

Context for the current turn.

authHandlerId

string

Authorization handler ID.

options
AuthorizationHandlerTokenOptions

Optional connection and scope overrides.

Returns

Promise<TokenResponse>

The exchanged token response.

exchangeToken(TurnContext, string[], string)

Warning

This API is now deprecated.

Use the overload that accepts an authorization handler ID followed by options.

Exchanges the user token for the requested scopes.

function exchangeToken(context: TurnContext, scopes: string[], authHandlerId: string): Promise<TokenResponse>

Parameters

context
TurnContext

Context for the current turn.

scopes

string[]

Scopes requested for the exchanged token.

authHandlerId

string

Authorization handler ID.

Returns

Promise<TokenResponse>

The exchanged token response.

exchangeTokenAsTokenCredential(TurnContext, string, AuthorizationHandlerTokenOptions)

Creates a credential that exchanges the current turn's user token.

function exchangeTokenAsTokenCredential(context: TurnContext, authHandlerId: string, options?: AuthorizationHandlerTokenOptions): TokenCredential

Parameters

context
TurnContext

Context for the current turn.

authHandlerId

string

Authorization handler ID.

options
AuthorizationHandlerTokenOptions

Optional connection and scope overrides.

Returns

A turn-scoped token credential.

getToken(TurnContext, string)

Gets the user token for an authorization handler.

function getToken(context: TurnContext, authHandlerId: string): Promise<TokenResponse>

Parameters

context
TurnContext

Context for the current turn.

authHandlerId

string

Authorization handler ID.

Returns

Promise<TokenResponse>

The token response.

getTokenAsTokenCredential(TurnContext, string)

Creates a credential backed by the current turn's user token.

function getTokenAsTokenCredential(context: TurnContext, authHandlerId: string): TokenCredential

Parameters

context
TurnContext

Context for the current turn.

authHandlerId

string

Authorization handler ID.

Returns

A turn-scoped token credential.

onSignInFailure((context: TurnContext, state: TurnState, authHandlerId?: string, errorMessage?: string) => Promise<void>)

Registers a callback for failed sign-in.

function onSignInFailure(handler: (context: TurnContext, state: TurnState, authHandlerId?: string, errorMessage?: string) => Promise<void>)

Parameters

handler

(context: TurnContext, state: TurnState, authHandlerId?: string, errorMessage?: string) => Promise<void>

Callback invoked after sign-in fails.

onSignInSuccess((context: TurnContext, state: TurnState, authHandlerId?: string) => Promise<void>)

Registers a callback for successful sign-in.

function onSignInSuccess(handler: (context: TurnContext, state: TurnState, authHandlerId?: string) => Promise<void>)

Parameters

handler

(context: TurnContext, state: TurnState, authHandlerId?: string) => Promise<void>

Callback invoked after sign-in succeeds.

signOut(TurnContext, TurnState, string)

Signs out the user from one or all authorization handlers.

function signOut(context: TurnContext, state: TurnState, authHandlerId?: string): Promise<void>

Parameters

context
TurnContext

Context for the current turn.

state
TurnState

State for the current turn.

authHandlerId

string

Handler to sign out from, or undefined for all handlers.

Returns

Promise<void>

A promise that resolves after sign-out completes.