From 576775f52b7aec73439cd83a61e39f4bef691954 Mon Sep 17 00:00:00 2001 From: rootdarkarchon Date: Tue, 3 Jan 2023 03:21:42 +0100 Subject: [PATCH] stop caching jwt per url but instead per auth key (chances they are the same between servers are low) --- MareSynchronos/WebAPI/ApiController.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/MareSynchronos/WebAPI/ApiController.cs b/MareSynchronos/WebAPI/ApiController.cs index 8c5a094..fdbb44a 100644 --- a/MareSynchronos/WebAPI/ApiController.cs +++ b/MareSynchronos/WebAPI/ApiController.cs @@ -32,7 +32,7 @@ public partial class ApiController : IDisposable, IMareHubClient private readonly FileCacheManager _fileDbManager; private CancellationTokenSource _connectionCancellationTokenSource; private Dictionary _jwtToken = new(StringComparer.Ordinal); - private KeyValuePair AuthorizationJwtHeader => new("Authorization", "Bearer " + _jwtToken[ApiUri]); + private KeyValuePair AuthorizationJwtHeader => new("Authorization", "Bearer " + _jwtToken[SecretKey]); private HubConnection? _mareHub; @@ -173,7 +173,7 @@ public partial class ApiController : IDisposable, IMareHubClient { Logger.Debug("Building connection"); - if (!_jwtToken.TryGetValue(ApiUri, out var jwtToken) || forceGetToken) + if (!_jwtToken.TryGetValue(SecretKey, out var jwtToken) || forceGetToken) { Logger.Debug("Requesting new JWT token"); using HttpClient httpClient = new(); @@ -187,7 +187,7 @@ public partial class ApiController : IDisposable, IMareHubClient new KeyValuePair("auth", auth) })).ConfigureAwait(false); result.EnsureSuccessStatusCode(); - _jwtToken[ApiUri] = await result.Content.ReadAsStringAsync().ConfigureAwait(false); + _jwtToken[SecretKey] = await result.Content.ReadAsStringAsync().ConfigureAwait(false); Logger.Debug("JWT Token Success"); }