From b129f22b739abd2c034d4a9bd8e3474272d359e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9E=D0=BB=D1=8F=20=D0=91=D0=B8=D0=B7=D1=8E=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0?= Date: Fri, 31 Jan 2025 17:04:05 +0500 Subject: [PATCH] =?UTF-8?q?=D0=BC=D0=B8=D0=BD=D0=B8-=D1=80=D0=B5=D1=84?= =?UTF-8?q?=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DD.Persistence.Client/Helpers/ApiTokenHelper.cs | 10 +++++----- .../TestHttpClientFactory.cs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/DD.Persistence.Client/Helpers/ApiTokenHelper.cs b/DD.Persistence.Client/Helpers/ApiTokenHelper.cs index 85fa428..4a46016 100644 --- a/DD.Persistence.Client/Helpers/ApiTokenHelper.cs +++ b/DD.Persistence.Client/Helpers/ApiTokenHelper.cs @@ -19,7 +19,7 @@ public static class ApiTokenHelper /// /// /// - public static async Task Authorize(this HttpClient httpClient, IConfiguration configuration) + public static void Authorize(this HttpClient httpClient, IConfiguration configuration) { var authUser = configuration .GetSection(nameof(AuthUser)) @@ -30,7 +30,7 @@ public static class ApiTokenHelper var keycloakGetTokenUrl = configuration.GetSection("KeycloakGetTokenUrl").Get() ?? string.Empty; var jwtToken = needUseKeyCloak - ? await authUser.CreateKeyCloakJwtToken(keycloakGetTokenUrl) + ? authUser.CreateKeyCloakJwtToken(keycloakGetTokenUrl) : authUser.CreateDefaultJwtToken(); httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtToken); @@ -73,7 +73,7 @@ public static class ApiTokenHelper /// /// /// - private static async Task CreateKeyCloakJwtToken(this AuthUser authUser, string keycloakGetTokenUrl) + private static string CreateKeyCloakJwtToken(this AuthUser authUser, string keycloakGetTokenUrl) { var sharedClient = new HttpClient(); var parameters = new Dictionary { @@ -84,11 +84,11 @@ public static class ApiTokenHelper }; var encodedContent = new FormUrlEncodedContent(parameters); - using HttpResponseMessage response = await sharedClient.PostAsync(keycloakGetTokenUrl, encodedContent); + using HttpResponseMessage response = sharedClient.PostAsync(keycloakGetTokenUrl, encodedContent).GetAwaiter().GetResult(); if (response.IsSuccessStatusCode == true) { - var data = await response.Content.ReadAsStreamAsync(); + var data = response.Content.ReadAsStreamAsync().GetAwaiter().GetResult(); var token = JsonSerializer.Deserialize(data)!; return token.AccessToken; } diff --git a/DD.Persistence.IntegrationTests/TestHttpClientFactory.cs b/DD.Persistence.IntegrationTests/TestHttpClientFactory.cs index 4c0cd04..51b8783 100644 --- a/DD.Persistence.IntegrationTests/TestHttpClientFactory.cs +++ b/DD.Persistence.IntegrationTests/TestHttpClientFactory.cs @@ -19,7 +19,7 @@ namespace DD.Persistence.IntegrationTests public HttpClient CreateClient(string name) { var client = factory.CreateClient(); - client.Authorize(configuration).GetAwaiter().GetResult(); + client.Authorize(configuration); return client; }