/// <summary> /// Initializes a new instance of the <see cref="ConfigurationBotFrameworkAuthentication"/> class. /// </summary> /// <param name="credentialsFactory">An IServiceClientCredentialsFactory instance.</param> /// <param name="authConfiguration">An AuthenticationConfiguration instance.</param> /// <param name="httpClient">A custom HttpClient to use.</param> /// <param name="logger">The ILogger instance to use.</param> public ConfigurationBotFrameworkAuthentication(ServiceClientCredentialsFactory credentialsFactory = null, AuthenticationConfiguration authConfiguration = null, HttpClient httpClient = null, ILogger logger = null) { var channelService = ConfigurationManager.AppSettings["ChannelService"]; var validateAuthority = ConfigurationManager.AppSettings["ValidateAuthority"]; var toChannelFromBotLoginUrl = ConfigurationManager.AppSettings["ToChannelFromBotLoginUrl"]; var toChannelFromBotOAuthScope = ConfigurationManager.AppSettings["ToChannelFromBotOAuthScope"]; var toBotFromChannelTokenIssuer = ConfigurationManager.AppSettings["ToBotFromChannelTokenIssuer"]; var oAuthUrl = ConfigurationManager.AppSettings["OAuthUrl"]; var toBotFromChannelOpenIdMetadataUrl = ConfigurationManager.AppSettings["ToBotFromChannelOpenIdMetadataUrl"]; var toBotFromEmulatorOpenIdMetadataUrl = ConfigurationManager.AppSettings["ToBotFromEmulatorOpenIdMetadataUrl"]; var callerId = ConfigurationManager.AppSettings["CallerId"]; _inner = BotFrameworkAuthenticationFactory.Create( channelService, bool.Parse(validateAuthority ?? "true"), toChannelFromBotLoginUrl, toChannelFromBotOAuthScope, toBotFromChannelTokenIssuer, oAuthUrl, toBotFromChannelOpenIdMetadataUrl, toBotFromEmulatorOpenIdMetadataUrl, callerId, credentialsFactory ?? new ConfigurationServiceClientCredentialFactory(), authConfiguration ?? new AuthenticationConfiguration(), httpClient, logger); }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationBotFrameworkAuthentication"/> class. /// </summary> /// <param name="configuration">An IConfiguration instance.</param> /// <param name="credentialsFactory">An IServiceClientCredentialsFactory instance.</param> /// <param name="authConfiguration">An AuthenticationConfiguration instance.</param> /// <param name="httpClient">A custom HttpClient to use.</param> /// <param name="logger">The ILogger instance to use.</param> public ConfigurationBotFrameworkAuthentication(IConfiguration configuration, ServiceClientCredentialsFactory credentialsFactory = null, AuthenticationConfiguration authConfiguration = null, HttpClient httpClient = null, ILogger logger = null) { var channelService = configuration.GetSection("ChannelService")?.Value; var validateAuthority = configuration.GetSection("ValidateAuthority")?.Value; var toChannelFromBotLoginUrl = configuration.GetSection("ToChannelFromBotLoginUrl")?.Value; var toChannelFromBotOAuthScope = configuration.GetSection("ToChannelFromBotOAuthScope")?.Value; var toBotFromChannelTokenIssuer = configuration.GetSection("ToBotFromChannelTokenIssuer")?.Value; var oAuthUrl = configuration.GetSection("OAuthUrl")?.Value; var toBotFromChannelOpenIdMetadataUrl = configuration.GetSection("ToBotFromChannelOpenIdMetadataUrl")?.Value; var toBotFromEmulatorOpenIdMetadataUrl = configuration.GetSection("ToBotFromEmulatorOpenIdMetadataUrl")?.Value; var callerId = configuration.GetSection("CallerId")?.Value; _inner = BotFrameworkAuthenticationFactory.Create( channelService, bool.Parse(validateAuthority ?? "true"), toChannelFromBotLoginUrl, toChannelFromBotOAuthScope, toBotFromChannelTokenIssuer, oAuthUrl, toBotFromChannelOpenIdMetadataUrl, toBotFromEmulatorOpenIdMetadataUrl, callerId, credentialsFactory ?? new ConfigurationServiceClientCredentialFactory(configuration), authConfiguration ?? new AuthenticationConfiguration(), httpClient, logger); }
/// <summary> /// Initializes a new instance of the <see cref="ConfigurationServiceClientCredentialFactory"/> class. /// </summary> /// <param name="configuration">An instance of <see cref="IConfiguration"/>.</param> /// <param name="httpClient">A httpClient to use.</param> /// <param name="logger">A logger to use.</param> public ConfigurationServiceClientCredentialFactory(IConfiguration configuration, HttpClient httpClient = null, ILogger logger = null) { var appType = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppTypeKey)?.Value; var appId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppIdKey)?.Value; var password = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppPasswordKey)?.Value; var tenantId = configuration.GetSection(MicrosoftAppCredentials.MicrosoftAppTenantIdKey)?.Value; var parsedAppType = Enum.TryParse(appType, ignoreCase: true, out MicrosoftAppType parsed) ? parsed : MicrosoftAppType.MultiTenant; // default switch (parsedAppType) { case MicrosoftAppType.UserAssignedMsi: if (string.IsNullOrWhiteSpace(appId)) { throw new ArgumentException($"{MicrosoftAppCredentials.MicrosoftAppIdKey} is required for MSI in configuration."); } if (string.IsNullOrWhiteSpace(tenantId)) { throw new ArgumentException($"{MicrosoftAppCredentials.MicrosoftAppTenantIdKey} is required for MSI in configuration."); } if (!string.IsNullOrWhiteSpace(password)) { throw new ArgumentException($"{MicrosoftAppCredentials.MicrosoftAppPasswordKey} must not be set for MSI in configuration."); } _inner = new ManagedIdentityServiceClientCredentialsFactory(appId, new JwtTokenProviderFactory(), httpClient, logger); break; case MicrosoftAppType.SingleTenant: if (string.IsNullOrWhiteSpace(appId)) { throw new ArgumentException($"{MicrosoftAppCredentials.MicrosoftAppIdKey} is required for SingleTenant in configuration."); } if (string.IsNullOrWhiteSpace(tenantId)) { throw new ArgumentException($"{MicrosoftAppCredentials.MicrosoftAppTenantIdKey} is required for SingleTenant in configuration."); } if (string.IsNullOrWhiteSpace(password)) { throw new ArgumentException($"{MicrosoftAppCredentials.MicrosoftAppPasswordKey} is required for SingleTenant in configuration."); } _inner = new PasswordServiceClientCredentialFactory(appId, password, tenantId, httpClient, logger); break; default: // MultiTenant _inner = new PasswordServiceClientCredentialFactory(appId, password, tenantId: string.Empty, httpClient, logger); break; } }