public static Bot CreateAndValidateWebBot(AzureBotServiceClient botServiceMgmtClient, string rgname, string kind = null) { string botid = TestUtilities.GenerateName("botservice"); Bot resource = CreateDefaultBotResource(); if (string.IsNullOrEmpty(kind)) { resource.Kind = Kind.Function; } BotDeploymentInfo deployInfo = new BotDeploymentInfo(); Bot responseResource = null; if (resource.Kind == Kind.Function) { responseResource = botServiceMgmtClient.Bots.CreateFunctionBot(rgname, botid, resource, deployInfo); VerifyBotServiceProperties(resource, responseResource, isRegistrationBot: false); } else { responseResource = botServiceMgmtClient.Bots.CreateWebAppBot(rgname, botid, resource, deployInfo); VerifyBotServiceProperties(resource, responseResource, isRegistrationBot: false); } return(responseResource); }
public static AzureBotServiceClient GetBotServiceManagementClient(MockContext context, RecordedDelegatingHandler handler) { AzureBotServiceClient botClient; if (IsTestTenant) { botClient = new AzureBotServiceClient(new TokenCredentials("xyz"), GetHandler()); botClient.SubscriptionId = testSubscription; botClient.BaseUri = testUri; } else { handler.IsPassThrough = true; botClient = context.GetServiceClient <AzureBotServiceClient>(handlers: handler); botClient.HttpClient.DefaultRequestHeaders.Add("x-ms-client-principal-name", "*****@*****.**"); } return(botClient); }
public static Bot CreateAndValidateBot(AzureBotServiceClient botServiceMgmtClient, string rgname, string kind = null) { string botid = TestUtilities.GenerateName("botservice"); Bot resource = CreateDefaultBotResource(); if (!string.IsNullOrEmpty(kind)) { resource.Kind = kind; } var responseResource = botServiceMgmtClient.Bots.CreateWithHttpMessagesAsync(rgname, botid, resource).GetAwaiter().GetResult().Body; VerifyBotServiceProperties(resource, responseResource); return(responseResource); }
private static async Task <MsaAppIdInfo> GetOrCreateMsaAppId(AzureBotServiceClient client, Bot parameters, string tenantId, string resourceName) { MsaAppIdInfo appInfo = new MsaAppIdInfo(); // If an MsaAppId is provided, then we use it. Otherwise, we provision one. if (string.IsNullOrEmpty(parameters.Properties.MsaAppId)) { #if NET452 // Obtain user token with bot first party app as audience var authenticator = new MsaAuthenticator(tenantId); #endif #if NETSTANDARD1_4 // Obtain user token with bot first party app as audience var authenticator = new MsaAuthenticator(tenantId, client.DeviceCodeAuthCallback); #endif var authResult = await authenticator.AcquireTokenAsync().ConfigureAwait(false); // Provision msa app id and password var msaAppProvider = new MsaAppProvider(authResult); appInfo = await msaAppProvider.ProvisionApp(resourceName).ConfigureAwait(false); parameters.Properties.MsaAppId = appInfo.AppId; } else { if (string.IsNullOrEmpty(parameters.Properties.MsaAppPassword)) { throw new ArgumentException(nameof(parameters.Properties.MsaAppPassword)); } appInfo.AppId = parameters.Properties.MsaAppId; appInfo.Password = parameters.Properties.MsaAppPassword; } return(appInfo); }