From 0bddda9b4bf2a8ecabd3773f72a0d46d11a812cc Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Tue, 26 Mar 2024 16:42:01 +0100 Subject: [PATCH 1/2] Move Bearer to constant --- EventsHandler/Api/EventsHandler/Constants/DefaultValues.cs | 2 ++ .../EventsHandler/Services/DataReceiving/JwtHttpSupplier.cs | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/EventsHandler/Api/EventsHandler/Constants/DefaultValues.cs b/EventsHandler/Api/EventsHandler/Constants/DefaultValues.cs index fdfeafae..1c3f96e5 100644 --- a/EventsHandler/Api/EventsHandler/Constants/DefaultValues.cs +++ b/EventsHandler/Api/EventsHandler/Constants/DefaultValues.cs @@ -44,6 +44,8 @@ internal static class Authorization internal static class OpenApiSecurityScheme { internal static string BearerFormat => "JWT"; + + internal static string BearerSchema => "Bearer"; } } #endregion diff --git a/EventsHandler/Api/EventsHandler/Services/DataReceiving/JwtHttpSupplier.cs b/EventsHandler/Api/EventsHandler/Services/DataReceiving/JwtHttpSupplier.cs index fafaeda1..eb42172c 100644 --- a/EventsHandler/Api/EventsHandler/Services/DataReceiving/JwtHttpSupplier.cs +++ b/EventsHandler/Api/EventsHandler/Services/DataReceiving/JwtHttpSupplier.cs @@ -118,7 +118,8 @@ private HttpClient AuthorizeWithJwt(HttpClient httpClient) this._configuration.User.Authorization.JWT.UserName()); // Set Authorization header - httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwtToken); + httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue( + DefaultValues.Authorization.OpenApiSecurityScheme.BearerSchema, jwtToken); return httpClient; } From 721fc6d5cc965b54a197eef371c49c4504c289ca Mon Sep 17 00:00:00 2001 From: "Thomas M. Krystyan" Date: Tue, 26 Mar 2024 16:48:41 +0100 Subject: [PATCH 2/2] Introducing a little more detailed error logging --- .../Api/EventsHandler/Services/DataQuerying/ApiDataQuery.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/EventsHandler/Api/EventsHandler/Services/DataQuerying/ApiDataQuery.cs b/EventsHandler/Api/EventsHandler/Services/DataQuerying/ApiDataQuery.cs index da92ec23..8de23741 100644 --- a/EventsHandler/Api/EventsHandler/Services/DataQuerying/ApiDataQuery.cs +++ b/EventsHandler/Api/EventsHandler/Services/DataQuerying/ApiDataQuery.cs @@ -95,7 +95,7 @@ internal async Task ProcessGetAsync(HttpClientTypes httpsClientT (bool isSuccess, string jsonResult) = await this._httpSupplier.GetAsync(httpsClientType, organizationId, uri); return isSuccess ? this._serializer.Deserialize(jsonResult) - : throw new HttpRequestException(fallbackErrorMessage); + : throw new HttpRequestException($"{fallbackErrorMessage} | URI: {uri} | JSON response: {jsonResult}"); } /// @@ -111,7 +111,7 @@ internal async Task ProcessPostAsync(HttpClientTypes httpsClient (bool isSuccess, string jsonResult) = await this._httpSupplier.PostAsync(httpsClientType, organizationId, uri, body); return isSuccess ? this._serializer.Deserialize(jsonResult) - : throw new HttpRequestException(fallbackErrorMessage); + : throw new HttpRequestException($"{fallbackErrorMessage} | URI: {uri} | JSON response: {jsonResult}"); } #region Internal query methods