Search Unity

Resolved HTTP/1.1 401 Unauthorized

Discussion in 'Lobby' started by TheDelhiDuck, Jul 25, 2022.

Thread Status:
Not open for further replies.
  1. TheDelhiDuck

    TheDelhiDuck

    Joined:
    Aug 29, 2014
    Posts:
    35
    Hi I've been getting "HTTP/1.1 401 Unauthorized" errors in the editor when executing lobby functions, but only after exiting play mode and running again. I'm currently using Unity 2021.3.1f1.32 with com.unity.services.lobby 1.0.1

    The problem goes away when I force a domain reload by re-importing a script.

    I am logging out and clearing the session token when exiting play mode by doing the following.

    Code (CSharp):
    1. AuthenticationService.Instance.SignOut(true);
    But even after doing this, it will work the first time until exiting play mode and I hit play again. What may I be doing wrong? Is there something else I need to do to cleanup after exiting play mode so I don't have to force domain reload?
     
    Last edited: Jul 25, 2022
  2. TheDelhiDuck

    TheDelhiDuck

    Joined:
    Aug 29, 2014
    Posts:
    35
    Seems I shouldn't actually call SignOut when exiting play mode. Having removed it, I can successfully use the LobbyAPI after hitting stop, then play again.
     
  3. veleek_unity

    veleek_unity

    Ben Randall Unity Technologies

    Joined:
    Aug 25, 2021
    Posts:
    59
    Glad you figured it out. You might not _need_ to call sign-out, but it shouldn't prevent it from working. Were you calling SignOut on exit and SignIn the next time it started? If you did that and it still wasn't working then there might be a bug for us to fix.
     
  4. TheDelhiDuck

    TheDelhiDuck

    Joined:
    Aug 29, 2014
    Posts:
    35
    Thanks for the reply. I would do the SignInAnonymouslyAsync at start then check the value of AuthenticationService.Instance.IsSignedIn was true to verify sign in was successful.

    In the situation when I was signing out on shut down, both runs indicated successful sign in.
    But 404 errors would occur on the second run when using the LobbyApi.
    When debugging I could see that the _accessToken in the various lobby apis was null second time round, while first time around it had a valid looking token.
     
  5. veleek_unity

    veleek_unity

    Ben Randall Unity Technologies

    Joined:
    Aug 25, 2021
    Posts:
    59
    Interesting... thanks for the details! I'm going to mark this thread as resolved, but I'll create a bug for the authentication team to try and verify this!
     
    TheDelhiDuck likes this.
Thread Status:
Not open for further replies.