From 9df5750f1cc5f3db147b10387e9c49095b86d22f Mon Sep 17 00:00:00 2001 From: Mathias Beaulieu-Duncan Date: Sat, 21 Dec 2024 02:07:13 -0500 Subject: [PATCH] part of last commit --- OpenHarbor.JwtTokenManager/JwtTokenManagerService.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/OpenHarbor.JwtTokenManager/JwtTokenManagerService.cs b/OpenHarbor.JwtTokenManager/JwtTokenManagerService.cs index c978798..99d32f1 100644 --- a/OpenHarbor.JwtTokenManager/JwtTokenManagerService.cs +++ b/OpenHarbor.JwtTokenManager/JwtTokenManagerService.cs @@ -10,6 +10,7 @@ namespace OpenHarbor.JwtTokenManager; public class JwtTokenManagerService(JwtTokenManagerOptions options, IHttpClientFactory httpClientFactory, ILogger? logger, IMemoryCache? memoryCache, JwtTokenManagerCacheOptions cacheOptions) : IJwtTokenManagerService { + private readonly HttpClient _httpClient = httpClientFactory.CreateClient(); private readonly TimeSpan _cacheExpirationOffset = TimeSpan.FromSeconds(cacheOptions.ExpirationOffset); private readonly string _scopes = string.Join(" ", options.Scopes); @@ -29,9 +30,7 @@ public class JwtTokenManagerService(JwtTokenManagerOptions options, IHttpClientF return cachedToken; } } - - var client = httpClientFactory.CreateClient(); - + var formContent = new FormUrlEncodedContent([ new KeyValuePair("grant_type", "client_credentials"), new KeyValuePair("client_id", options.ClientId), @@ -46,7 +45,7 @@ public class JwtTokenManagerService(JwtTokenManagerOptions options, IHttpClientF request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - var response = await client.SendAsync(request, cancellationToken); + var response = await _httpClient.SendAsync(request, cancellationToken); response.EnsureSuccessStatusCode();