UNPKG

@microsoft/teams-ai

Version:

SDK focused on building AI based applications for Microsoft Teams.

75 lines 3.32 kB
"use strict"; // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. Object.defineProperty(exports, "__esModule", { value: true }); exports.getUserToken = getUserToken; exports.getSignInResource = getSignInResource; exports.signOutUser = signOutUser; exports.exchangeToken = exchangeToken; /** * @internal * @private * Retrieves the user token for a given connection name and magic code. * @param {TurnContext} context The context object for the current turn of conversation. * @param {OAuthPromptSettings} settings The settings for the OAuth prompt. * @param {string} magicCode The magic code to use for token retrieval. * @returns {Promise<TokenResponse>} A TokenResponse object containing the user token. */ async function getUserToken(context, settings, magicCode) { const userTokenClient = context.turnState.get(context.adapter.UserTokenClientKey); if (userTokenClient) { return userTokenClient.getUserToken(context.activity?.from?.id, settings.connectionName, context.activity?.channelId, magicCode); } else { throw new Error('OAuth prompt is not supported by the current adapter'); } } /** * @internal * @private * @param {TurnContext} context The context object for the current turn of conversation. * @param {OAuthPromptSettings} settings The settings for the OAuth prompt. * @returns {Promise<SignInUrlResponse>} A SignInUrlResponse object containing the sign-in URL. */ async function getSignInResource(context, settings) { const userTokenClient = context.turnState.get(context.adapter.UserTokenClientKey); if (userTokenClient) { return userTokenClient.getSignInResource(settings.connectionName, context.activity, ''); } else { throw new Error('OAuth prompt is not supported by the current adapter'); } } /** * @internal * @private * @param {TurnContext} context The context object for the current turn of conversation. * @param {OAuthPromptSettings} settings The settings for the OAuth prompt. */ async function signOutUser(context, settings) { const userTokenClient = context.turnState.get(context.adapter.UserTokenClientKey); if (userTokenClient) { await userTokenClient.signOutUser(context.activity?.from?.id, settings.connectionName, context.activity?.channelId); } else { throw new Error('OAuth prompt is not supported by the current adapter'); } } /** * @internal * @private * @param {TurnContext} context The context object for the current turn of conversation. * @param {OAuthPromptSettings} settings The settings for the OAuth prompt. * @param {TokenExchangeRequest} tokenExchangeRequest The token exchange request details to be sent to the Bot Framework Token Service. * @returns {Promise<TokenResponse>} A TokenResponse object containing the user token. */ async function exchangeToken(context, settings, tokenExchangeRequest) { const userTokenClient = context.turnState.get(context.adapter.UserTokenClientKey); if (userTokenClient) { return userTokenClient.exchangeToken(context.activity?.from?.id, settings.connectionName, context.activity?.channelId, tokenExchangeRequest); } else { throw new Error('OAuth prompt is not supported by the current adapter'); } } //# sourceMappingURL=UserTokenAccess.js.map