From cd03d2991f31616d0275c2f14818f57661778a27 Mon Sep 17 00:00:00 2001 From: trawzified <55751269+tr4wzified@users.noreply.github.com> Date: Fri, 31 May 2024 01:03:31 +0200 Subject: [PATCH] OAuth Nexus fixes (#2569) * Missing a lock in the validate method that could cause refresh to trigger a lot of times asynchronously * Fix refreshing Nexus OAuth token not working properly * Fix accidental deadlock on NexusApi.Validate(), add extra validation logging --- Wabbajack.Downloaders.Dispatcher/DownloadDispatcher.cs | 3 ++- Wabbajack.Downloaders.Nexus/NexusDownloader.cs | 3 ++- Wabbajack.Networking.NexusApi/NexusApi.cs | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Wabbajack.Downloaders.Dispatcher/DownloadDispatcher.cs b/Wabbajack.Downloaders.Dispatcher/DownloadDispatcher.cs index c01eb31e..5511a58b 100644 --- a/Wabbajack.Downloaders.Dispatcher/DownloadDispatcher.cs +++ b/Wabbajack.Downloaders.Dispatcher/DownloadDispatcher.cs @@ -148,8 +148,9 @@ public class DownloadDispatcher return result; } - catch (HttpException) + catch (HttpException ex) { + _logger.LogError($"Failed verifying {a.State.PrimaryKeyString}: {ex}"); await _verificationCache.Put(a.State, false); return false; } diff --git a/Wabbajack.Downloaders.Nexus/NexusDownloader.cs b/Wabbajack.Downloaders.Nexus/NexusDownloader.cs index 74a86805..1168cb5c 100644 --- a/Wabbajack.Downloaders.Nexus/NexusDownloader.cs +++ b/Wabbajack.Downloaders.Nexus/NexusDownloader.cs @@ -217,8 +217,9 @@ public class NexusDownloader : ADownloader, IUrlDownloader return fileInfo.info.FileId == state.FileID; } - catch (HttpException) + catch (HttpException ex) { + _logger.LogError($"HttpException: {ex} on {archive.Name}"); return false; } } diff --git a/Wabbajack.Networking.NexusApi/NexusApi.cs b/Wabbajack.Networking.NexusApi/NexusApi.cs index b512d265..77d56277 100644 --- a/Wabbajack.Networking.NexusApi/NexusApi.cs +++ b/Wabbajack.Networking.NexusApi/NexusApi.cs @@ -188,7 +188,6 @@ public class NexusApi protected virtual async ValueTask GenerateMessage(HttpMethod method, string uri, params object?[] parameters) { - using var _ = await _authLock.WaitAsync(); var msg = new HttpRequestMessage(); msg.Method = method; @@ -232,6 +231,7 @@ public class NexusApi private async ValueTask<(bool IsApiKey, string code)> GetAuthInfo() { + using var _ = await _authLock.WaitAsync(); if (AuthInfo.HaveToken()) { var info = await AuthInfo.Get(); @@ -272,6 +272,8 @@ public class NexusApi var response = await _client.PostAsync($"https://users.nexusmods.com/oauth/token", content, cancel); var responseString = await response.Content.ReadAsStringAsync(cancel); var newJwt = JsonSerializer.Deserialize(responseString); + if (newJwt != null) + newJwt.ReceivedAt = DateTime.UtcNow.ToFileTimeUtc(); state.OAuth = newJwt; await AuthInfo.SetToken(state);