Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when logging out during 2FA email verification #26834

Merged
merged 1 commit into from
Jan 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions osu.Game/Online/API/OAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,12 @@ private bool ensureAccessToken()
// if we already have a valid access token, let's use it.
if (accessTokenValid) return true;

// we want to ensure only a single authentication update is happening at once.
lock (access_token_retrieval_lock)
{
// re-check if valid, in case another request completed and revalidated our access.
if (accessTokenValid) return true;

// if not, let's try using our refresh token to request a new access token.
if (!string.IsNullOrEmpty(Token.Value?.RefreshToken))
// ReSharper disable once PossibleNullReferenceException
AuthenticateWithRefresh(Token.Value.RefreshToken);
// if not, let's try using our refresh token to request a new access token.
if (!string.IsNullOrEmpty(Token.Value?.RefreshToken))
// ReSharper disable once PossibleNullReferenceException
AuthenticateWithRefresh(Token.Value.RefreshToken);

return accessTokenValid;
}
return accessTokenValid;
}

private bool accessTokenValid => Token.Value?.IsValid ?? false;
Expand All @@ -149,14 +142,18 @@ private bool ensureAccessToken()

internal string RequestAccessToken()
{
if (!ensureAccessToken()) return null;
lock (access_token_retrieval_lock)
{
if (!ensureAccessToken()) return null;

return Token.Value.AccessToken;
return Token.Value.AccessToken;
}
}

internal void Clear()
{
Token.Value = null;
lock (access_token_retrieval_lock)
Token.Value = null;
}

private class AccessTokenRequestRefresh : AccessTokenRequest
Expand Down
Loading