diff --git a/src/Admin/Controllers/HomeController.cs b/src/Admin/Controllers/HomeController.cs index 9497be03aa..20c1be70d0 100644 --- a/src/Admin/Controllers/HomeController.cs +++ b/src/Admin/Controllers/HomeController.cs @@ -11,17 +11,13 @@ namespace Bit.Admin.Controllers; public class HomeController : Controller { private readonly GlobalSettings _globalSettings; - private readonly HttpClient _httpClient; + private readonly HttpClient _httpClient = new HttpClient(); private readonly ILogger _logger; - public HomeController( - GlobalSettings globalSettings, - ILogger logger, - IHttpClientFactory httpClientFactory) + public HomeController(GlobalSettings globalSettings, ILogger logger) { _globalSettings = globalSettings; _logger = logger; - _httpClient = httpClientFactory.CreateClient(); } [Authorize] diff --git a/src/Admin/Jobs/AliveJob.cs b/src/Admin/Jobs/AliveJob.cs index 2e8de43275..b97d597e58 100644 --- a/src/Admin/Jobs/AliveJob.cs +++ b/src/Admin/Jobs/AliveJob.cs @@ -8,16 +8,14 @@ namespace Bit.Admin.Jobs; public class AliveJob : BaseJob { private readonly GlobalSettings _globalSettings; - private readonly HttpClient _httpClient; + private HttpClient _httpClient = new HttpClient(); public AliveJob( GlobalSettings globalSettings, - ILogger logger, - IHttpClientFactory httpClientFactory) + ILogger logger) : base(logger) { _globalSettings = globalSettings; - _httpClient = httpClientFactory.CreateClient(); } protected async override Task ExecuteJobAsync(IJobExecutionContext context) diff --git a/src/Api/Dirt/Controllers/HibpController.cs b/src/Api/Dirt/Controllers/HibpController.cs index 0d05b94e7e..f12027cb31 100644 --- a/src/Api/Dirt/Controllers/HibpController.cs +++ b/src/Api/Dirt/Controllers/HibpController.cs @@ -16,24 +16,27 @@ public class HibpController : Controller { private const string HibpBreachApi = "https://haveibeenpwned.com/api/v3/breachedaccount/{0}" + "?truncateResponse=false&includeUnverified=false"; - private readonly HttpClient _httpClient; + private static HttpClient _httpClient; private readonly IUserService _userService; private readonly ICurrentContext _currentContext; private readonly GlobalSettings _globalSettings; private readonly string _userAgent; + static HibpController() + { + _httpClient = new HttpClient(); + } + public HibpController( IUserService userService, ICurrentContext currentContext, - GlobalSettings globalSettings, - IHttpClientFactory httpClientFactory) + GlobalSettings globalSettings) { _userService = userService; _currentContext = currentContext; _globalSettings = globalSettings; _userAgent = _globalSettings.SelfHosted ? "Bitwarden Self-Hosted" : "Bitwarden"; - _httpClient = httpClientFactory.CreateClient(); } [HttpGet("breach")] diff --git a/src/Billing/Controllers/FreshsalesController.cs b/src/Billing/Controllers/FreshsalesController.cs index d825a2d071..0182011d7a 100644 --- a/src/Billing/Controllers/FreshsalesController.cs +++ b/src/Billing/Controllers/FreshsalesController.cs @@ -1,4 +1,5 @@ -using System.Text.Json.Serialization; +using System.Net.Http.Headers; +using System.Text.Json.Serialization; using Bit.Core.Billing.Enums; using Bit.Core.Repositories; using Bit.Core.Settings; @@ -24,16 +25,23 @@ public class FreshsalesController : Controller IOrganizationRepository organizationRepository, IOptions billingSettings, ILogger logger, - GlobalSettings globalSettings, - IHttpClientFactory httpClientFactory) + GlobalSettings globalSettings) { _userRepository = userRepository; _organizationRepository = organizationRepository; _logger = logger; _globalSettings = globalSettings; - _httpClient = httpClientFactory.CreateClient("Freshsales"); + + _httpClient = new HttpClient + { + BaseAddress = new Uri("https://bitwarden.freshsales.io/api/") + }; _freshsalesApiKey = billingSettings.Value.FreshsalesApiKey; + + _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( + "Token", + $"token={_freshsalesApiKey}"); } diff --git a/src/Billing/Startup.cs b/src/Billing/Startup.cs index 63ed23c3d2..afb01f4801 100644 --- a/src/Billing/Startup.cs +++ b/src/Billing/Startup.cs @@ -10,7 +10,6 @@ using Bit.Core.Settings; using Bit.Core.Utilities; using Bit.SharedWeb.Utilities; using Microsoft.Extensions.DependencyInjection.Extensions; -using Microsoft.Extensions.Options; using Quartz; using Stripe; @@ -103,15 +102,6 @@ public class Startup { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", billingSettings.Onyx.ApiKey); }); - services.AddHttpClient("Freshsales", (sp, client) => - { - var billingSettings = sp.GetRequiredService>().Value; - client.BaseAddress = new Uri("https://bitwarden.freshsales.io/api/"); - client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( - "Token", - $"token={billingSettings.FreshsalesApiKey}" - ); - }); services.AddScoped(); services.AddScoped(); diff --git a/test/Billing.Test/Controllers/FreshsalesControllerTests.cs b/test/Billing.Test/Controllers/FreshsalesControllerTests.cs index c9eb8c8e40..c9ae6efb1a 100644 --- a/test/Billing.Test/Controllers/FreshsalesControllerTests.cs +++ b/test/Billing.Test/Controllers/FreshsalesControllerTests.cs @@ -31,18 +31,12 @@ public class FreshsalesControllerTests var globalSettings = new GlobalSettings(); globalSettings.BaseServiceUri.Admin = "https://test.com"; - var httpClientFactory = Substitute.For(); - httpClientFactory - .CreateClient("Freshsales") - .Returns(new HttpClient()); - var sut = new FreshsalesController( userRepository, organizationRepository, billingSettings, Substitute.For>(), - globalSettings, - httpClientFactory + globalSettings ); return (sut, userRepository, organizationRepository); diff --git a/util/Setup/Program.cs b/util/Setup/Program.cs index 68f5447c5f..a951cbe17d 100644 --- a/util/Setup/Program.cs +++ b/util/Setup/Program.cs @@ -285,7 +285,6 @@ public class Program url = $"{installationUrl}/installations/"; } - var response = new HttpClient().GetAsync(url + _context.Install.InstallationId).GetAwaiter().GetResult(); if (!response.IsSuccessStatusCode)