botframework-connector
Version:
Bot Connector is autorest generated connector client.
75 lines • 3.54 kB
JavaScript
;
/**
* @module botframework-connector
*/
// Copyright (c) Microsoft Corporation.
// 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.MsalServiceClientCredentialsFactory = void 0;
const msalAppCredentials_1 = require("./msalAppCredentials");
const authenticationConstants_1 = require("./authenticationConstants");
const governmentConstants_1 = require("./governmentConstants");
/**
* An implementation of ServiceClientCredentialsFactory that generates MsalAppCredentials
*/
class MsalServiceClientCredentialsFactory {
/**
* Create an MsalServiceClientCredentialsFactory instance using runtime configuration and an
* `@azure/msal-node` `ConfidentialClientApplication`.
*
* @param appId App ID for validation.
* @param clientApplication An `@azure/msal-node` `ConfidentialClientApplication` instance.
*/
constructor(appId, clientApplication) {
this.clientApplication = clientApplication;
this.appId = appId;
}
/**
* @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* () {
return !this.appId;
});
}
/**
* @inheritdoc
*/
createCredentials(appId, audience, loginEndpoint, _validateAuthority) {
return __awaiter(this, void 0, void 0, function* () {
if (yield this.isAuthenticationDisabled()) {
return msalAppCredentials_1.MsalAppCredentials.Empty;
}
if (!(yield this.isValidAppId(appId))) {
throw new Error('Invalid appId.');
}
const normalizedEndpoint = loginEndpoint.toLowerCase();
if (normalizedEndpoint.startsWith(authenticationConstants_1.AuthenticationConstants.ToChannelFromBotLoginUrlPrefix)) {
return new msalAppCredentials_1.MsalAppCredentials(this.clientApplication, appId, undefined, audience || authenticationConstants_1.AuthenticationConstants.ToBotFromChannelTokenIssuer);
}
if (normalizedEndpoint.startsWith(governmentConstants_1.GovernmentConstants.ToChannelFromBotLoginUrlPrefix)) {
return new msalAppCredentials_1.MsalAppCredentials(this.clientApplication, appId, undefined, audience || governmentConstants_1.GovernmentConstants.ToChannelFromBotOAuthScope);
}
return new msalAppCredentials_1.MsalAppCredentials(this.clientApplication, appId, loginEndpoint, audience);
});
}
}
exports.MsalServiceClientCredentialsFactory = MsalServiceClientCredentialsFactory;
//# sourceMappingURL=msalServiceClientCredentialsFactory.js.map