From 4d5cc5d9b19b62e6c4ec25d71e02ca2d96990aaa Mon Sep 17 00:00:00 2001 From: Stanley Dimant Date: Thu, 6 Feb 2025 10:46:07 +0100 Subject: [PATCH] maybe fix getting key shit --- .../ServerConfiguration/ServerConfigurationManager.cs | 8 ++++---- MareSynchronos/WebAPI/SignalR/TokenProvider.cs | 11 ++++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs b/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs index d60c732..42a5013 100644 --- a/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs +++ b/MareSynchronos/Services/ServerConfiguration/ServerConfigurationManager.cs @@ -104,24 +104,24 @@ public class ServerConfigurationManager var auth = currentServer.Authentications.FindAll(f => string.Equals(f.CharacterName, charaName) && f.WorldId == worldId); if (auth.Count >= 2) { - _logger.LogTrace("GetSecretKey accessed, returning null because multiple ({count}) identical characters.", auth.Count); + _logger.LogTrace("GetOAuth2 accessed, returning null because multiple ({count}) identical characters.", auth.Count); hasMulti = true; return null; } if (auth.Count == 0) { - _logger.LogTrace("GetSecretKey accessed, returning null because no set up characters for {chara} on {world}", charaName, worldId); + _logger.LogTrace("GetOAuth2 accessed, returning null because no set up characters for {chara} on {world}", charaName, worldId); return null; } if (!string.IsNullOrEmpty(auth.Single().UID) && !string.IsNullOrEmpty(currentServer.OAuthToken)) { - _logger.LogTrace("GetSecretKey accessed, returning {key} ({keyValue}) for {chara} on {world}", auth.Single().UID, string.Join("", currentServer.OAuthToken.Take(10)), charaName, worldId); + _logger.LogTrace("GetOAuth2 accessed, returning {key} ({keyValue}) for {chara} on {world}", auth.Single().UID, string.Join("", currentServer.OAuthToken.Take(10)), charaName, worldId); return (currentServer.OAuthToken, auth.Single().UID!); } - _logger.LogTrace("GetSecretKey accessed, returning null because no UID found for {chara} on {world} or OAuthToken is not configured.", charaName, worldId); + _logger.LogTrace("GetOAuth2 accessed, returning null because no UID found for {chara} on {world} or OAuthToken is not configured.", charaName, worldId); return null; } diff --git a/MareSynchronos/WebAPI/SignalR/TokenProvider.cs b/MareSynchronos/WebAPI/SignalR/TokenProvider.cs index c6678cd..bd46f65 100644 --- a/MareSynchronos/WebAPI/SignalR/TokenProvider.cs +++ b/MareSynchronos/WebAPI/SignalR/TokenProvider.cs @@ -162,17 +162,22 @@ public sealed class TokenProvider : IDisposable, IMediatorSubscriber if (_serverManager.CurrentServer.UseOAuth2) { - var oauthInfo = _serverManager.GetOAuth2(out _)!; + var (OAuthToken, UID) = _serverManager.GetOAuth2(out _) + ?? throw new InvalidOperationException("Requested OAuth2 but received null"); + jwtIdentifier = new(_serverManager.CurrentApiUrl, playerIdentifier, - oauthInfo.Value.UID, oauthInfo.Value.OAuthToken); + UID, OAuthToken); } else { + var secretKey = _serverManager.GetSecretKey(out _) + ?? throw new InvalidOperationException("Requested SecretKey but received null"); + jwtIdentifier = new(_serverManager.CurrentApiUrl, playerIdentifier, string.Empty, - _serverManager.GetSecretKey(out _)!); + secretKey); } _lastJwtIdentifier = jwtIdentifier; }