playgameservices / play-games-plugin-for-unity

Google Play Games plugin for Unity
Other
3.45k stars 959 forks source link

Unable to log in after logging out #1856

Open Tanek81 opened 7 years ago

Tanek81 commented 7 years ago

I am experiencing a strange behaviour while testing this plugin.

Situation: the game is published, the app on the GPG section of my dashboard is ready but not published (I won't publish until my code and all the tests will make my game ready to be deployed in Alpha version), my account is set as a tester, I am testing a build with GPG integration on my tablet (Nvidia Shield Tablet, Android 5.1.1) and on my phone (Nexus 5, Android 6.0.1), Unity 5.6.1, plugin version 0.39.9a (latest). Everything is working fine, I can log in, I see my app and the requested authorizations in my Google account ("App connected to your account"), I can unlock and see test achievements, I can log out, I still have to implement cloud save and leaderboards so those will tested in a later stage.

The strange behaviour happens when I log out (by my custom button or by the GPG provided "log out" in the menu while browsing achievements) and then I try to log in again, I was testing this flow having in mind a possible log out by mistake. After logging out there is no way I can log in again, I tried closing the game and reopening it (I have implemented an automatic login on game opening) and I retried when the game opened by tapping on my custom "log in" button (which of course does the same thing), in both cases the plugin shows the log in flow, then asks me to choose an account, I tap to choose the only account I have and then it does not authenticate me. I have also tried removing the authorization from "App connected to your account" and sometimes this solves the situation after some retries, when it's not solved the login flow does not ask the confirmation for allowing the app to have the requested information (the usual "allow/deny" window), so it stops earlier its flow. That is confirmed also by the fact that the plugin is not calling GPG for authorization as I have no evidence of traffic in the Google Cloud dashboard. As per today I have not found a flow to solve this issue, this means that right now on my device I cannot go on testing because I cannot log in (but please bear in mind that everything is working in a "normal" situation, I have tested it). I don't know if this issue is related only to the testing phase with the GPG app not published, I also searched for similar issues but found nothing (I am sure I am not the only one testing a log out -> log in flow ;) ), right now for me this is quite blocking.

The logs while trying to log in:

07-31 15:14:32.360: I/Unity(17295): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
07-31 15:14:32.449: I/Unity(17295):  [Play Games Plugin DLL] 07/31/17 15:14:32 +02:00 DEBUG: Starting Auth Transition. Op: SIGN_IN status: ERROR_NOT_AUTHORIZED
07-31 15:14:32.449: I/Unity(17295):  
07-31 15:14:32.449: I/Unity(17295): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
07-31 15:14:32.449: I/Unity(17295):  [Play Games Plugin DLL] 07/31/17 15:14:32 +02:00 DEBUG: AuthState == Unauthenticated calling auth callbacks with failure
07-31 15:14:32.449: I/Unity(17295):  
07-31 15:14:32.449: I/Unity(17295): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
07-31 15:14:32.460: I/Unity(17295): Error, not authenticated
07-31 15:14:32.460: I/Unity(17295):  
07-31 15:14:32.460: I/Unity(17295): (Filename: ./artifacts/generated/common/runtime/DebugBindings.gen.cpp Line: 51)
07-31 15:14:32.472: I/Unity(17295):  [Play Games Plugin DLL] 07/31/17 15:14:32 +02:00 DEBUG: Invoking user callback on game thread

Code for logging in and logging out (it's a very simple flow right now, copied from the plugin examples):

public bool IsAuthenticated {
    get {
        return Social.localUser.authenticated;
    }
}

public string UserName {
    get {
        if (IsAuthenticated) {
            return Social.localUser.userName;
        } else {
            return "";
        }
    }
}

public void Login () {
    // authenticate user:
    if (!IsAuthenticated) {
        // Authenticate
        Social.localUser.Authenticate ((bool success) => {
            if (success) {
                Debug.Log ("Logged: " + UserName);
            } else {
                Debug.Log ("Error, not authenticated");
            }
        });
    }
}

public void Logout () {
    ((PlayGamesPlatform)Social.Active).SignOut();
}

Please let me know if you need anything else and thank you.

claywilkinson commented 7 years ago

Can you share an unfiltered log of attempting to sign in the second time?

Tanek81 commented 7 years ago

Hi Clay, first of all thank you for your support.

By looking again at the unfiltered log, I think I have identified one possible cause of this issue:

08-01 17:03:28.887: W/Auth(7870): [GetToken] GetToken failed with status code: INVALID_AUDIENCE 08-01 17:03:28.888: E/TokenRequestor(7857): You have wrong OAuth2 related configurations, please check. Detailed error: INVALID_AUDIENCE 08-01 17:03:28.900: I/SignInActivity(17503): Transition from 6 to 11 08-01 17:03:28.900: W/SignInActivity(17503): onSignInFailed()... 08-01 17:03:28.900: W/SignInActivity(17503): Sign in failed during 6 08-01 17:03:28.900: W/SignInActivity(17503): ==> Returning non-OK result: 10002

I noticed this because the Web App Client ID I inserted at the beginning of the integration was actually wrong, it is something I already fixed this morning while going on with the plugin integration along with Firebase (it was an easy find as of course I rechecked everything connected to Firebase, including the OAuth2 token). I took a small leap of faith (I was afraid to be again unable to test on my device) and I just tested the reported flow with the updated test app and it seems to work correctly.

So I think this can be reproduced in this way:

  1. Integrate plugin and during the setup insert a wrong Web App Client ID (e.g.: I wrongly inserted the auto generated one for my Android app instead of the Web App Client generated by Firebase)
  2. In the config for the initialization there was a ".RequestIdToken()" but no ".RequestServerAuthCode(false)" (I don't know if this can be related, but I had no code for accessing tokens)
  3. Build for Android
  4. Test the login --> it works
  5. Test the logged user (e.g.: show achievements) --> it works.
  6. Test the logout --> it works
  7. Test again the login --> it does not log in (never again, I managed to find a partial workaround by removing the app in "App connected to your account" dashboard and clearing data and cache for both Google Play Services and GPG on the device)

Of course I should have inserted the correct Web App Client ID from the beginning but the strange thing is that the login worked without any problem (even starting again the app) unless I did a logout, then everything stopped working. Let me know if I can help further, if needed I can also checkout the exact commit I used yesterday and then change only the Web App Client ID to confirm my thoughts (now that I know that this can be solved I am more willing to retry this flow ;) ).

claywilkinson commented 7 years ago

You are correct - INVALID_AUDIENCE usually indicates a problem with the web client id. Which version of the plugin are you using? There was a version where it logs in twice, once via the C++ SDK which does not know about the webclient id/auth code and one via the TokenClient - which calls the Java SDK via JNI and that one does understand the web client id.

It sounds like from your description that the C++ one finishes first then when you log out, the java one finished first with the failure?

This should be fixed in 0.9.39a.

Tanek81 commented 7 years ago

I am using latest plugin version:

plugin version 0.39.9a (latest)

j1and1 commented 6 years ago

So whats the status with this!? Ran into same issue today.......

I am using 0.9.40

aneeshpanoli commented 6 years ago

going through the same nightmare for the last 24hrs.