diff --git a/Web/Resgrid.Web.Eventing/Startup.cs b/Web/Resgrid.Web.Eventing/Startup.cs index 1e7c36ee..6ce3cc55 100644 --- a/Web/Resgrid.Web.Eventing/Startup.cs +++ b/Web/Resgrid.Web.Eventing/Startup.cs @@ -101,7 +101,7 @@ public void ConfigureServices(IServiceCollection services) if (Config.ApiConfig.BypassSslChecks) { - services.AddHttpClient("Name") + services.AddHttpClient("ByPassSSLHttpClient") .ConfigurePrimaryHttpMessageHandler(() => { var handler = new HttpClientHandler @@ -115,6 +115,10 @@ public void ConfigureServices(IServiceCollection services) return handler; }); } + else + { + services.AddHttpClient("ByPassSSLHttpClient"); + } services.AddCors(); diff --git a/Web/Resgrid.Web.ServicesCore/Startup.cs b/Web/Resgrid.Web.ServicesCore/Startup.cs index f2ba07aa..8cff3de2 100644 --- a/Web/Resgrid.Web.ServicesCore/Startup.cs +++ b/Web/Resgrid.Web.ServicesCore/Startup.cs @@ -124,7 +124,7 @@ public void ConfigureServices(IServiceCollection services) if (Config.ApiConfig.BypassSslChecks) { - services.AddHttpClient("Name") + services.AddHttpClient("ByPassSSLHttpClient") .ConfigurePrimaryHttpMessageHandler(() => { var handler = new HttpClientHandler @@ -138,6 +138,10 @@ public void ConfigureServices(IServiceCollection services) return handler; }); } + else + { + services.AddHttpClient("ByPassSSLHttpClient"); + } services.AddScoped, IdentityUserStore>(); services.AddScoped, IdentityRoleStore>(); diff --git a/Web/Resgrid.WebCore/Helpers/ApiAuthHelper.cs b/Web/Resgrid.WebCore/Helpers/ApiAuthHelper.cs index 6db547fd..013344c6 100644 --- a/Web/Resgrid.WebCore/Helpers/ApiAuthHelper.cs +++ b/Web/Resgrid.WebCore/Helpers/ApiAuthHelper.cs @@ -1,4 +1,6 @@ -using IdentityModel.Client; +using CommonServiceLocator; +using IdentityModel.Client; +using Microsoft.AspNetCore.Http; using Newtonsoft.Json; using System; using System.Dynamic; @@ -10,9 +12,14 @@ namespace Resgrid.WebCore.Helpers { public class ApiAuthHelper { + private static IHttpClientFactory _httpClientFactory; + public static async Task GetBearerApiTokenAsync(string username, string password) { - HttpClient client = new HttpClient(); + if (_httpClientFactory == null) + _httpClientFactory = ServiceLocator.Current.GetInstance(); + + HttpClient client = _httpClientFactory.CreateClient("ByPassSSLHttpClient"); // Retrieve the OpenIddict server configuration document containing the endpoint URLs. var configuration = await client.GetDiscoveryDocumentAsync(Config.SystemBehaviorConfig.ResgridApiBaseUrl); if (configuration.IsError) diff --git a/Web/Resgrid.WebCore/Startup.cs b/Web/Resgrid.WebCore/Startup.cs index 935afc5f..cba0184b 100644 --- a/Web/Resgrid.WebCore/Startup.cs +++ b/Web/Resgrid.WebCore/Startup.cs @@ -106,7 +106,7 @@ public void ConfigureServices(IServiceCollection services) if (Config.ApiConfig.BypassSslChecks) { - services.AddHttpClient("Name") + services.AddHttpClient("ByPassSSLHttpClient") .ConfigurePrimaryHttpMessageHandler(() => { var handler = new HttpClientHandler @@ -120,6 +120,10 @@ public void ConfigureServices(IServiceCollection services) return handler; }); } + else + { + services.AddHttpClient("ByPassSSLHttpClient"); + } services.AddScoped, IdentityUserStore>(); services.AddScoped, IdentityRoleStore>();