botframework-connector
Version:
Bot Connector is autorest generated connector client.
56 lines • 2.63 kB
JavaScript
;
/**
* @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.ManagedIdentityAppCredentials = void 0;
const assert_1 = require("assert");
const appCredentials_1 = require("./appCredentials");
const managedIdentityAuthenticator_1 = require("./managedIdentityAuthenticator");
/**
* Managed Service Identity auth implementation.
*/
class ManagedIdentityAppCredentials extends appCredentials_1.AppCredentials {
/**
* Managed Identity for AAD credentials auth and caching.
*
* @param appId Client ID for the managed identity assigned to the bot.
* @param oAuthScope The scope for the token.
* @param tokenProviderFactory The JWT token provider factory to use.
*/
constructor(appId, oAuthScope, tokenProviderFactory) {
super(appId, null, oAuthScope);
(0, assert_1.ok)(appId === null || appId === void 0 ? void 0 : appId.trim(), 'ManagedIdentityAppCredentials.constructor(): missing appId.');
(0, assert_1.ok)(tokenProviderFactory, 'ManagedIdentityAppCredentials.constructor(): missing tokenProviderFactory.');
this.tokenProviderFactory = tokenProviderFactory;
super.appId = appId;
this.authenticator = new managedIdentityAuthenticator_1.ManagedIdentityAuthenticator(this.appId, this.oAuthScope, this.tokenProviderFactory);
}
/**
* @inheritdoc
*/
refreshToken() {
return __awaiter(this, void 0, void 0, function* () {
const token = yield this.authenticator.getToken();
return {
accessToken: token.token,
expiresOn: new Date(token.expiresOnTimestamp),
};
});
}
}
exports.ManagedIdentityAppCredentials = ManagedIdentityAppCredentials;
//# sourceMappingURL=managedIdentityAppCredentials.js.map