botframework-connector
Version:
Bot Connector is autorest generated connector client.
58 lines • 6.06 kB
JavaScript
;
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.BotFrameworkAuthenticationFactory = void 0;
const authenticationConstants_1 = require("./authenticationConstants");
const botframework_schema_1 = require("botframework-schema");
const governmentConstants_1 = require("./governmentConstants");
const parameterizedBotFrameworkAuthentication_1 = require("./parameterizedBotFrameworkAuthentication");
const botbuilder_stdlib_1 = require("botbuilder-stdlib");
/**
* A factory for [BotFrameworkAuthentication](xref:botframework-connector.BotFrameworkAuthentication) which encapsulates the environment specific Bot Framework Protocol auth code.
*/
class BotFrameworkAuthenticationFactory {
/**
* @param maybeChannelService The Channel Service.
* @param maybeValidateAuthority The validate authority value to use.
* @param maybeToChannelFromBotLoginUrl The to Channel from bot login url.
* @param maybeToChannelFromBotOAuthScope The to Channel from bot oauth scope.
* @param maybeToBotFromChannelTokenIssuer The to bot from Channel Token Issuer.
* @param maybeOAuthUrl The oAuth url.
* @param maybeToBotFromChannelOpenIdMetadataUrl The to bot from Channel Open Id Metadata url.
* @param maybeToBotFromEmulatorOpenIdMetadataUrl The to bot from Emulator Open Id Metadata url.
* @param maybeCallerId The callerId set on on authenticated [Activities](xref:botframework-schema.Activity).
* @param maybeCredentialFactory The [ServiceClientCredentialsFactory](xref:botframework-connector.ServiceClientCredentialsFactory) to use to create credentials.
* @param maybeAuthConfiguration The [AuthenticationConfiguration](xref:botframework-connector.AuthenticationConfiguration) to use.
* @param maybeBotFrameworkClientFetch The fetch to use in BotFrameworkClient.
* @param maybeConnectorClientOptions The [ConnectorClientOptions](xref:botframework-connector.ConnectorClientOptions) to use when creating ConnectorClients.
* @returns A new [BotFrameworkAuthentication](xref:botframework-connector.BotFrameworkAuthentication) instance.
*/
static create(maybeChannelService, maybeValidateAuthority, maybeToChannelFromBotLoginUrl, maybeToChannelFromBotOAuthScope, maybeToBotFromChannelTokenIssuer, maybeOAuthUrl, maybeToBotFromChannelOpenIdMetadataUrl, maybeToBotFromEmulatorOpenIdMetadataUrl, maybeCallerId, maybeCredentialFactory, maybeAuthConfiguration, maybeBotFrameworkClientFetch, maybeConnectorClientOptions = {}) {
if (!botbuilder_stdlib_1.stringExt.isNilOrEmpty(maybeToChannelFromBotLoginUrl) ||
!botbuilder_stdlib_1.stringExt.isNilOrEmpty(maybeToChannelFromBotOAuthScope) ||
!botbuilder_stdlib_1.stringExt.isNilOrEmpty(maybeToBotFromChannelTokenIssuer) ||
!botbuilder_stdlib_1.stringExt.isNilOrEmpty(maybeOAuthUrl) ||
!botbuilder_stdlib_1.stringExt.isNilOrEmpty(maybeToBotFromChannelOpenIdMetadataUrl) ||
!botbuilder_stdlib_1.stringExt.isNilOrEmpty(maybeToBotFromEmulatorOpenIdMetadataUrl) ||
!botbuilder_stdlib_1.stringExt.isNilOrEmpty(maybeCallerId)) {
// If any of the 'parameterized' properties are defined, assume all parameters are intentional.
return new parameterizedBotFrameworkAuthentication_1.ParameterizedBotFrameworkAuthentication(maybeValidateAuthority, maybeToChannelFromBotLoginUrl, maybeToChannelFromBotOAuthScope, maybeToBotFromChannelTokenIssuer, maybeOAuthUrl, maybeToBotFromChannelOpenIdMetadataUrl, maybeToBotFromEmulatorOpenIdMetadataUrl, maybeCallerId, maybeCredentialFactory, maybeAuthConfiguration, maybeBotFrameworkClientFetch, maybeConnectorClientOptions);
}
else {
// else apply the built in default behavior, which is either the public cloud or the gov cloud depending on whether we have a channelService value present
if (botbuilder_stdlib_1.stringExt.isNilOrEmpty(maybeChannelService)) {
return new parameterizedBotFrameworkAuthentication_1.ParameterizedBotFrameworkAuthentication(true, authenticationConstants_1.AuthenticationConstants.ToChannelFromBotLoginUrl, authenticationConstants_1.AuthenticationConstants.ToChannelFromBotOAuthScope, authenticationConstants_1.AuthenticationConstants.ToBotFromChannelTokenIssuer, authenticationConstants_1.AuthenticationConstants.OAuthUrl, authenticationConstants_1.AuthenticationConstants.ToBotFromChannelOpenIdMetadataUrl, authenticationConstants_1.AuthenticationConstants.ToBotFromEmulatorOpenIdMetadataUrl, botframework_schema_1.CallerIdConstants.PublicAzureChannel, maybeCredentialFactory, maybeAuthConfiguration, maybeBotFrameworkClientFetch, maybeConnectorClientOptions);
}
else if (maybeChannelService === governmentConstants_1.GovernmentConstants.ChannelService) {
return new parameterizedBotFrameworkAuthentication_1.ParameterizedBotFrameworkAuthentication(true, governmentConstants_1.GovernmentConstants.ToChannelFromBotLoginUrl, governmentConstants_1.GovernmentConstants.ToChannelFromBotOAuthScope, governmentConstants_1.GovernmentConstants.ToBotFromChannelTokenIssuer, governmentConstants_1.GovernmentConstants.OAuthUrl, governmentConstants_1.GovernmentConstants.ToBotFromChannelOpenIdMetadataUrl, governmentConstants_1.GovernmentConstants.ToBotFromEmulatorOpenIdMetadataUrl, botframework_schema_1.CallerIdConstants.USGovChannel, maybeCredentialFactory, maybeAuthConfiguration, maybeBotFrameworkClientFetch, maybeConnectorClientOptions);
}
else {
// The ChannelService value is used an indicator of which built in set of constants to use. If it is not recognized, a full configuration is expected.
throw new Error('The provided ChannelService value is not supported.');
}
}
}
}
exports.BotFrameworkAuthenticationFactory = BotFrameworkAuthenticationFactory;
//# sourceMappingURL=botFrameworkAuthenticationFactory.js.map