botframework-connector
Version:
Bot Connector is autorest generated connector client.
63 lines • 2.57 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.UserTokenClient = void 0;
const z = __importStar(require("zod"));
const botframework_schema_1 = require("botframework-schema");
/**
* Client for access user token service.
*/
class UserTokenClient {
/**
* Helper function to create the Base64 encoded token exchange state used in getSignInResource calls.
*
* @param appId The appId to include in the token exchange state.
* @param connectionName The connectionName to include in the token exchange state.
* @param activity The [Activity](xref:botframework-schema.Activity) from which to derive the token exchange state.
* @returns Base64 encoded token exchange state.
*/
static createTokenExchangeState(appId, connectionName, activity) {
z.object({
appId: z.string(),
connectionName: z.string(),
activity: z.record(z.unknown()),
}).parse({
appId,
connectionName,
activity,
});
const tokenExchangeState = {
connectionName,
conversation: botframework_schema_1.ActivityEx.getConversationReference(activity),
relatesTo: activity.relatesTo,
msAppId: appId,
};
return Buffer.from(JSON.stringify(tokenExchangeState)).toString('base64');
}
}
exports.UserTokenClient = UserTokenClient;
//# sourceMappingURL=userTokenClient.js.map