HTTP/1.1 401 Unauthorized

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.

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?

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.

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.

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.

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!

1 Like