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
This commit is contained in:
trawzified 2024-05-31 01:03:31 +02:00 committed by GitHub
parent f956943f45
commit cd03d2991f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 3 deletions

View File

@ -148,8 +148,9 @@ public class DownloadDispatcher
return result; return result;
} }
catch (HttpException) catch (HttpException ex)
{ {
_logger.LogError($"Failed verifying {a.State.PrimaryKeyString}: {ex}");
await _verificationCache.Put(a.State, false); await _verificationCache.Put(a.State, false);
return false; return false;
} }

View File

@ -217,8 +217,9 @@ public class NexusDownloader : ADownloader<Nexus>, IUrlDownloader
return fileInfo.info.FileId == state.FileID; return fileInfo.info.FileId == state.FileID;
} }
catch (HttpException) catch (HttpException ex)
{ {
_logger.LogError($"HttpException: {ex} on {archive.Name}");
return false; return false;
} }
} }

View File

@ -188,7 +188,6 @@ public class NexusApi
protected virtual async ValueTask<HttpRequestMessage> GenerateMessage(HttpMethod method, string uri, protected virtual async ValueTask<HttpRequestMessage> GenerateMessage(HttpMethod method, string uri,
params object?[] parameters) params object?[] parameters)
{ {
using var _ = await _authLock.WaitAsync();
var msg = new HttpRequestMessage(); var msg = new HttpRequestMessage();
msg.Method = method; msg.Method = method;
@ -232,6 +231,7 @@ public class NexusApi
private async ValueTask<(bool IsApiKey, string code)> GetAuthInfo() private async ValueTask<(bool IsApiKey, string code)> GetAuthInfo()
{ {
using var _ = await _authLock.WaitAsync();
if (AuthInfo.HaveToken()) if (AuthInfo.HaveToken())
{ {
var info = await AuthInfo.Get(); 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 response = await _client.PostAsync($"https://users.nexusmods.com/oauth/token", content, cancel);
var responseString = await response.Content.ReadAsStringAsync(cancel); var responseString = await response.Content.ReadAsStringAsync(cancel);
var newJwt = JsonSerializer.Deserialize<JwtTokenReply>(responseString); var newJwt = JsonSerializer.Deserialize<JwtTokenReply>(responseString);
if (newJwt != null)
newJwt.ReceivedAt = DateTime.UtcNow.ToFileTimeUtc();
state.OAuth = newJwt; state.OAuth = newJwt;
await AuthInfo.SetToken(state); await AuthInfo.SetToken(state);