Authentication class

User authentication service.

Constructors

Authentication<TState>(Application<TState>, string, OAuthSettings | TeamsSsoSettings, Storage, MessageExtensionAuthenticationBase, BotAuthenticationBase<TState>, AdaptiveCardAuthenticationBase)

Creates a new instance of the Authentication class.

Properties

settings

The authentication settings.

Methods

isUserSignedIn(TurnContext)

Check if the user is signed, if they are then return the token.

onUserSignInFailure((context: TurnContext, state: TState, error: AuthError) => Promise<void>)

This handler function is called when the user sign in flow fails. This only applies if sign in was initiated by the user sending a message to the bot. This handler will not be triggered if a message extension triggered the authentication flow.

onUserSignInSuccess((context: TurnContext, state: TState) => Promise<void>)

The handler function is called when the user has successfully signed in. This only applies if sign in was initiated by the user sending a message to the bot. This handler will not be triggered if a message extension triggered the authentication flow.

signInUser(TurnContext, TState)

Signs in a user. This method will be called automatically by the Application class.

signOutUser(TurnContext, TState)

Signs out a user.

Constructor Details

Authentication<TState>(Application<TState>, string, OAuthSettings | TeamsSsoSettings, Storage, MessageExtensionAuthenticationBase, BotAuthenticationBase<TState>, AdaptiveCardAuthenticationBase)

Creates a new instance of the Authentication class.

new Authentication(app: Application<TState>, name: string, settings: OAuthSettings | TeamsSsoSettings, storage?: Storage, messageExtensionsAuth?: MessageExtensionAuthenticationBase, botAuth?: BotAuthenticationBase<TState>, adaptiveCardAuth?: AdaptiveCardAuthenticationBase)

Parameters

app

Application<TState>

The application instance.

name

string

The name of the connection.

settings

OAuthSettings | TeamsSsoSettings

Authentication settings.

storage

Storage

A storage instance otherwise Memory Storage is used.

messageExtensionsAuth

MessageExtensionAuthenticationBase

Handles message extension flow authentication.

botAuth

BotAuthenticationBase<TState>

Handles bot-flow authentication.

adaptiveCardAuth

AdaptiveCardAuthenticationBase

Handles adaptive card authentication.

Property Details

settings

The authentication settings.

settings: OAuthSettings | TeamsSsoSettings

Property Value

OAuthSettings | TeamsSsoSettings

Method Details

isUserSignedIn(TurnContext)

Check if the user is signed, if they are then return the token.

function isUserSignedIn(context: TurnContext): Promise<undefined | string>

Parameters

context

TurnContext

Current turn context.

Returns

Promise<undefined | string>

The token string or undefined if the user is not signed in.

onUserSignInFailure((context: TurnContext, state: TState, error: AuthError) => Promise<void>)

This handler function is called when the user sign in flow fails. This only applies if sign in was initiated by the user sending a message to the bot. This handler will not be triggered if a message extension triggered the authentication flow.

function onUserSignInFailure(handler: (context: TurnContext, state: TState, error: AuthError) => Promise<void>)

Parameters

handler

(context: TurnContext, state: TState, error: AuthError) => Promise<void>

The handler function to call when the user failed to signed in.

onUserSignInSuccess((context: TurnContext, state: TState) => Promise<void>)

The handler function is called when the user has successfully signed in. This only applies if sign in was initiated by the user sending a message to the bot. This handler will not be triggered if a message extension triggered the authentication flow.

function onUserSignInSuccess(handler: (context: TurnContext, state: TState) => Promise<void>)

Parameters

handler

(context: TurnContext, state: TState) => Promise<void>

The handler function to call when the user has successfully signed in

signInUser(TurnContext, TState)

Signs in a user. This method will be called automatically by the Application class.

function signInUser(context: TurnContext, state: TState): Promise<undefined | string>

Parameters

context

TurnContext

Current turn context.

state

TState

Application state.

Returns

Promise<undefined | string>

The authentication token or undefined if the user is still login in.

signOutUser(TurnContext, TState)

Signs out a user.

function signOutUser(context: TurnContext, state: TState): Promise<void>

Parameters

context

TurnContext

Current turn context.

state

TState

Application state.

Returns

Promise<void>

A Promise representing the asynchronous operation.