botframework-connector
Version:
Bot Connector is autorest generated connector client.
68 lines • 3.23 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.ManagedIdentityServiceClientCredentialsFactory = void 0;
const managedIdentityAppCredentials_1 = require("./managedIdentityAppCredentials");
const serviceClientCredentialsFactory_1 = require("./serviceClientCredentialsFactory");
const assert_1 = require("assert");
/**
* A Managed Identity implementation of the [ServiceClientCredentialsFactory](xref:botframework-connector.ServiceClientCredentialsFactory) abstract class.
*/
class ManagedIdentityServiceClientCredentialsFactory extends serviceClientCredentialsFactory_1.ServiceClientCredentialsFactory {
/**
* Initializes a new instance of the ManagedIdentityServiceClientCredentialsFactory class.
*
* @param appId Client ID for the managed identity assigned to the bot.
* @param tokenProviderFactory The JWT token provider factory to use.
*/
constructor(appId, tokenProviderFactory) {
super();
(0, assert_1.ok)(appId === null || appId === void 0 ? void 0 : appId.trim(), 'ManagedIdentityServiceClientCredentialsFactory.constructor(): missing appId.');
(0, assert_1.ok)(tokenProviderFactory, 'ManagedIdentityServiceClientCredentialsFactory.constructor(): missing tokenProviderFactory.');
this.appId = appId;
this.tokenProviderFactory = tokenProviderFactory;
}
/**
* @inheritdoc
*/
isValidAppId(appId) {
return __awaiter(this, void 0, void 0, function* () {
return appId === this.appId;
});
}
/**
* @inheritdoc
*/
isAuthenticationDisabled() {
return __awaiter(this, void 0, void 0, function* () {
// Auth is always enabled for MSI.
return false;
});
}
/**
* @inheritdoc
*/
createCredentials(appId, audience) {
return __awaiter(this, void 0, void 0, function* () {
(0, assert_1.ok)(yield this.isValidAppId(appId), 'ManagedIdentityServiceClientCredentialsFactory.createCredentials(): Invalid Managed ID.');
return new managedIdentityAppCredentials_1.ManagedIdentityAppCredentials(this.appId, audience, this.tokenProviderFactory);
});
}
}
exports.ManagedIdentityServiceClientCredentialsFactory = ManagedIdentityServiceClientCredentialsFactory;
//# sourceMappingURL=managedIdentityServiceClientCredentialsFactory.js.map