UNPKG

botframework-connector

Version:

Bot Connector is autorest generated connector client.

57 lines 2.89 kB
"use strict"; /** * @module botframework-connector */ /** * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. */ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ManagedIdentityAuthenticator = void 0; const assert_1 = require("assert"); const botbuilder_stdlib_1 = require("botbuilder-stdlib"); /** * Abstraction to acquire tokens from a Managed Service Identity. */ class ManagedIdentityAuthenticator { /** * Initializes a new instance of the ManagedIdentityAuthenticator class. * * @param appId Client id for the managed identity to be used for acquiring tokens. * @param resource Resource for which to acquire the token. * @param tokenProviderFactory The JWT token provider factory to use. */ constructor(appId, resource, tokenProviderFactory) { (0, assert_1.ok)(appId === null || appId === void 0 ? void 0 : appId.trim(), 'ManagedIdentityAuthenticator.constructor(): missing appId.'); (0, assert_1.ok)(resource === null || resource === void 0 ? void 0 : resource.trim(), 'ManagedIdentityAuthenticator.constructor(): missing resource.'); (0, assert_1.ok)(tokenProviderFactory, 'ManagedIdentityAuthenticator.constructor(): missing tokenProviderFactory.'); const scopePostfix = '/.default'; if (!resource.endsWith(scopePostfix)) { resource = `${resource}${scopePostfix}`; } this.resource = resource; this.tokenProvider = tokenProviderFactory.createAzureServiceTokenProvider(appId); } /** * Acquires the security token. * * @returns {Promise<AccessToken>} A promise with the `AccessToken` provided by the [IJwtTokenProviderFactory](xref:botframework-connector.IJwtTokenProviderFactory) class. */ getToken() { return __awaiter(this, void 0, void 0, function* () { // Retry gradually, starting from 10 ms up to 5 times. return (0, botbuilder_stdlib_1.retry)(() => this.tokenProvider.getToken(this.resource), 5, 10); }); } } exports.ManagedIdentityAuthenticator = ManagedIdentityAuthenticator; //# sourceMappingURL=managedIdentityAuthenticator.js.map