146 lines
No EOL
8.9 KiB
JavaScript
146 lines
No EOL
8.9 KiB
JavaScript
"use strict";
|
|
// 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.createServiceClientCredentialFactoryFromConfiguration = exports.ConfigurationServiceClientCredentialFactory = void 0;
|
|
const z = __importStar(require("zod"));
|
|
const assert_1 = require("assert");
|
|
const botframework_connector_1 = require("botframework-connector");
|
|
const MultiTenant = 'MultiTenant';
|
|
const SingleTenant = 'SingleTenant';
|
|
const UserAssignedMsi = 'UserAssignedMsi';
|
|
const TypedConfig = z
|
|
.object({
|
|
/**
|
|
* The ID assigned to your bot in the [Bot Framework Portal](https://dev.botframework.com/).
|
|
*/
|
|
MicrosoftAppId: z.string(),
|
|
/**
|
|
* The password assigned to your bot in the [Bot Framework Portal](https://dev.botframework.com/).
|
|
*/
|
|
MicrosoftAppPassword: z.string(),
|
|
/**
|
|
* The type of app id assigned to your bot in the [Bot Framework Portal](https://dev.botframework.com/).
|
|
*/
|
|
MicrosoftAppType: z.string(),
|
|
/**
|
|
* The tenant id assigned to your bot in the [Bot Framework Portal](https://dev.botframework.com/).
|
|
*/
|
|
MicrosoftAppTenantId: z.string(),
|
|
/**
|
|
* Certificate thumbprint to authenticate the appId against AAD.
|
|
*/
|
|
[botframework_connector_1.AuthenticationConstants.CertificateThumbprint]: z.string(),
|
|
/**
|
|
* Certificate key to authenticate the appId against AAD.
|
|
*/
|
|
[botframework_connector_1.AuthenticationConstants.CertificatePrivateKey]: z.string(),
|
|
})
|
|
.partial();
|
|
/**
|
|
* ServiceClientCredentialsFactory that uses a [ConfigurationServiceClientCredentialFactoryOptions](xref:botbuilder-core.ConfigurationServiceClientCredentialFactoryOptions) or a [Configuration](xref:botbuilder-dialogs-adaptive-runtime-core.Configuration) instance to build ServiceClientCredentials with an AppId and App Password.
|
|
*/
|
|
class ConfigurationServiceClientCredentialFactory extends botframework_connector_1.PasswordServiceClientCredentialFactory {
|
|
/**
|
|
* Initializes a new instance of the [ConfigurationServiceClientCredentialFactory](xref:botbuilder-core.ConfigurationServiceClientCredentialFactory) class.
|
|
*
|
|
* @param factoryOptions A [ConfigurationServiceClientCredentialFactoryOptions](xref:botbuilder-core.ConfigurationServiceClientCredentialFactoryOptions) object.
|
|
*/
|
|
constructor(factoryOptions = {}) {
|
|
var _a;
|
|
const { MicrosoftAppId = null, MicrosoftAppPassword = null, MicrosoftAppType = null, MicrosoftAppTenantId = null, [botframework_connector_1.AuthenticationConstants.CertificateThumbprint]: CertificateThumbprint = null, [botframework_connector_1.AuthenticationConstants.CertificatePrivateKey]: CertificatePrivateKey = null, } = TypedConfig.nonstrict().parse(factoryOptions);
|
|
super(MicrosoftAppId, MicrosoftAppPassword, MicrosoftAppTenantId);
|
|
const appType = (_a = MicrosoftAppType === null || MicrosoftAppType === void 0 ? void 0 : MicrosoftAppType.trim()) !== null && _a !== void 0 ? _a : MultiTenant;
|
|
const withCertificate = CertificateThumbprint || CertificatePrivateKey;
|
|
if (withCertificate) {
|
|
(0, assert_1.ok)(CertificateThumbprint === null || CertificateThumbprint === void 0 ? void 0 : CertificateThumbprint.trim(), 'CertificateThumbprint is required when using a Certificate in configuration.');
|
|
(0, assert_1.ok)(CertificatePrivateKey === null || CertificatePrivateKey === void 0 ? void 0 : CertificatePrivateKey.trim(), 'CertificatePrivateKey is required when using a Certificate in configuration.');
|
|
}
|
|
switch (appType.toLocaleLowerCase()) {
|
|
case UserAssignedMsi.toLocaleLowerCase():
|
|
(0, assert_1.ok)(MicrosoftAppId === null || MicrosoftAppId === void 0 ? void 0 : MicrosoftAppId.trim(), 'MicrosoftAppId is required for MSI in configuration.');
|
|
(0, assert_1.ok)(MicrosoftAppTenantId === null || MicrosoftAppTenantId === void 0 ? void 0 : MicrosoftAppTenantId.trim(), 'MicrosoftAppTenantId is required for MSI in configuration.');
|
|
(0, assert_1.ok)(!(MicrosoftAppPassword === null || MicrosoftAppPassword === void 0 ? void 0 : MicrosoftAppPassword.trim()), 'MicrosoftAppPassword must not be set for MSI in configuration.');
|
|
this.inner = new botframework_connector_1.ManagedIdentityServiceClientCredentialsFactory(MicrosoftAppId, new botframework_connector_1.JwtTokenProviderFactory());
|
|
break;
|
|
case SingleTenant.toLocaleLowerCase():
|
|
(0, assert_1.ok)(MicrosoftAppId === null || MicrosoftAppId === void 0 ? void 0 : MicrosoftAppId.trim(), 'MicrosoftAppId is required for SingleTenant in configuration.');
|
|
(0, assert_1.ok)(MicrosoftAppTenantId === null || MicrosoftAppTenantId === void 0 ? void 0 : MicrosoftAppTenantId.trim(), 'MicrosoftAppTenantId is required for SingleTenant in configuration.');
|
|
if (withCertificate) {
|
|
this.inner = new botframework_connector_1.CertificateServiceClientCredentialsFactory(MicrosoftAppId, CertificateThumbprint, CertificatePrivateKey, MicrosoftAppTenantId);
|
|
}
|
|
else {
|
|
(0, assert_1.ok)(MicrosoftAppPassword === null || MicrosoftAppPassword === void 0 ? void 0 : MicrosoftAppPassword.trim(), 'MicrosoftAppPassword is required for SingleTenant in configuration.');
|
|
this.inner = new botframework_connector_1.PasswordServiceClientCredentialFactory(MicrosoftAppId, MicrosoftAppPassword, MicrosoftAppTenantId);
|
|
}
|
|
break;
|
|
default:
|
|
//MultiTenant
|
|
if (withCertificate) {
|
|
(0, assert_1.ok)(MicrosoftAppId === null || MicrosoftAppId === void 0 ? void 0 : MicrosoftAppId.trim(), 'MicrosoftAppId is required for MultiTenant when using a Certificate in configuration.');
|
|
this.inner = new botframework_connector_1.CertificateServiceClientCredentialsFactory(MicrosoftAppId, CertificateThumbprint, CertificatePrivateKey);
|
|
}
|
|
else {
|
|
this.inner = new botframework_connector_1.PasswordServiceClientCredentialFactory(MicrosoftAppId, MicrosoftAppPassword, '');
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
isValidAppId(microsoftAppId) {
|
|
return this.inner.isValidAppId(microsoftAppId);
|
|
}
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
isAuthenticationDisabled() {
|
|
return this.inner.isAuthenticationDisabled();
|
|
}
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
createCredentials(microsoftAppId, audience, loginEndpoint, validateAuthority) {
|
|
return this.inner.createCredentials(microsoftAppId, audience, loginEndpoint, validateAuthority);
|
|
}
|
|
}
|
|
exports.ConfigurationServiceClientCredentialFactory = ConfigurationServiceClientCredentialFactory;
|
|
/**
|
|
* Creates a new instance of the [ConfigurationServiceClientCredentialFactory](xref:botbuilder-core.ConfigurationServiceClientCredentialFactory) class.
|
|
*
|
|
* @remarks
|
|
* The [Configuration](xref:botbuilder-dialogs-adaptive-runtime-core.Configuration) instance provided to the constructor should
|
|
* have the desired authentication values available at the root, using the properties of [ConfigurationServiceClientCredentialFactoryOptions](xref:botbuilder-core.ConfigurationServiceClientCredentialFactoryOptions) as its keys.
|
|
* @param configuration A [Configuration](xref:botbuilder-dialogs-adaptive-runtime-core.Configuration) instance.
|
|
* @returns A [ConfigurationServiceClientCredentialFactory](xref:botbuilder-core.ConfigurationServiceClientCredentialFactory) instance.
|
|
*/
|
|
function createServiceClientCredentialFactoryFromConfiguration(configuration) {
|
|
const factoryOptions = configuration.get();
|
|
return new ConfigurationServiceClientCredentialFactory(factoryOptions);
|
|
}
|
|
exports.createServiceClientCredentialFactoryFromConfiguration = createServiceClientCredentialFactoryFromConfiguration;
|
|
//# sourceMappingURL=configurationServiceClientCredentialFactory.js.map
|