Skip to content

Commit

Permalink
Fix authentication loss not handled correctly
Browse files Browse the repository at this point in the history
This handles the case where on initial API connection, the server
responds with an `Unauthorized` response. It doesn't perform this same
checking/handling on every API request, which is probably what we want
eventually.

Opting to not address the full issue because I know this is going to be
a long one (see
https://github.com/ppy/osu/blob/05c50c0f6cfafab359963586ec265ad4f143a46c/osu.Game/Online/API/APIAccess.cs#L233).
  • Loading branch information
peppy committed Jul 23, 2021
1 parent 05c50c0 commit 17168b8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions osu.Game/Online/API/APIAccess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ private void run()

var userReq = new GetUserRequest();

userReq.Failure += ex =>
{
if (ex.InnerException is WebException webException && webException.Message == @"Unauthorized")
{
log.Add(@"Login no longer valid");
Logout();
}
else
failConnectionProcess();
};
userReq.Success += u =>
{
localUser.Value = u;
Expand All @@ -167,6 +177,7 @@ private void run()
// getting user's friends is considered part of the connection process.
var friendsReq = new GetFriendsRequest();

friendsReq.Failure += _ => failConnectionProcess();
friendsReq.Success += res =>
{
friends.AddRange(res);
Expand Down

0 comments on commit 17168b8

Please sign in to comment.