TeamsSSOTokenExchangeMiddleware class

If the activity name is signin/tokenExchange, this middleware will attempt to exchange the token, and deduplicate the incoming call, ensuring only one exchange request is processed. If a user is signed into multiple Teams clients, the Bot could receive a "signin/tokenExchange" from each client. Each token exchange request for a specific user login will have an identical activity.value.id.

Only one of these token exchange requests should be processed by the bot. The others return StatusCodes.PRECONDITION_FAILED. For a distributed bot in production, this requires distributed storage ensuring only one token exchange is processed. This middleware supports CosmosDb storage found in botbuilder-azure, or MemoryStorage for local development.

Constructors

TeamsSSOTokenExchangeMiddleware(Storage, string)

Initializes a new instance of the TeamsSSOTokenExchangeMiddleware class.

Methods

onTurn(TurnContext, () => Promise<void>)

Called each time the bot receives a new request.

Constructor Details

TeamsSSOTokenExchangeMiddleware(Storage, string)

Initializes a new instance of the TeamsSSOTokenExchangeMiddleware class.

new TeamsSSOTokenExchangeMiddleware(storage: Storage, oAuthConnectionName: string)

Parameters

storage

Storage

The Storage to use for deduplication

oAuthConnectionName

string

The connection name to use for the single sign on token exchange

Method Details

onTurn(TurnContext, () => Promise<void>)

Called each time the bot receives a new request.

function onTurn(context: TurnContext, next: () => Promise<void>): Promise<void>

Parameters

context

TurnContext

Context for current turn of conversation with the user.

next

() => Promise<void>

Function to call to continue execution to the next step in the middleware chain.

Returns

Promise<void>