playgameservices / play-games-plugin-for-unity

Google Play Games plugin for Unity
Other
3.43k stars 953 forks source link

Wrong Authcode on response from Authentication #3186

Open FedeJure opened 1 year ago

FedeJure commented 1 year ago

This form is for reporting Unity Plugin issues only. To report an issue with the Play Games Service (non-SDK related), check Google Play Games Services Support. Once you've read this section and determined that your issue is appropriate for this repository, please delete this section.

Describe the bug On the response callback of Authentication method or Social.localUser.Authenticate method the second parameter (authcode) is "Success". Is not letting the token on that parameter.

To Reproduce Steps to reproduce the behavior:

  1. ___ Having all the plugin installed and working (with all the configuration on PlayConsole) and the current account added like tester
  2. ___ execute this code after Plugin initialization and activation (or any other variant that returns the authCode parameter): PlayGamesPlatform.Instance.Authenticate(Social.localUser,async (success, authCode) => { Debug.Log("AUTHCODE: "+ authCode); });
  3. ___ Observe (using Android LogCat or similar due this code only works on real mobiles) that the token logged is "Success"

Expected behavior Must return the authCode token to be able to execute AuthenticationService.Instance.SignInWithGooglePlayGamesAsync(authCode)

Observed behavior Authcode is an string but with the "Success" value.

Versions

Linux1230 commented 1 year ago

Hi, I have the same problem, did you find a solution or a workaround?

mmatinaho-dodreams commented 1 year ago

@FedeJure @Linux1230 Did you guys try the PlayGamesPlatform.Instance.RequestServerSideAccess after success from Authenticate?

Linux1230 commented 1 year ago

Hi, I tried this, yesterday and now it works. I just don't commented here my solution.


public Task SignInAsync()
        {
            try
            {
                SetupAuthenticationEvents();
                PlayGamesPlatform.Instance.Authenticate(RequestServerSideAccess);
            }
            catch (Exception e)
            {
                DebugManager.LogException(e);
                AuthenticationErrorHandler.InvokeError(e.StackTrace);
            }

            return Task.CompletedTask;
        }

        private void RequestServerSideAccess(SignInStatus signInStatus)
        {
            if (!(signInStatus == SignInStatus.Success))
            {
                return;
            }
            else
            {
                AuthenticationErrorHandler.InvokeError($"Sign in status: {signInStatus}");
            }

            PlayGamesPlatform.Instance.RequestServerSideAccess(
                false,
                (string token) => GooglePlayGamesSignIn(token)
            );
        }

        private async void GooglePlayGamesSignIn(string token)
        {
            try
            {
                await AuthenticationService.Instance.SignInWithGooglePlayGamesAsync(token);
            }
            catch (AuthenticationException ex)
            {
                AuthenticationErrorHandler.InvokeError(ex);
            }
            catch (RequestFailedException ex)
            {
                AuthenticationErrorHandler.InvokeError(ex);
            }
            catch (Exception ex)
            {
                AuthenticationErrorHandler.InvokeError(ex);
            }
        }
dkeele commented 1 year ago

Looks like the documentation says to call RequestServerSideAccess to get the authCode. Not sure why that string is passed at all.

To get the server side access code:

  1. Configure the web client id of the web application linked to your game in the Play Game Console.
  2. Call PlayGamesPlatform.Instance.RequestServerSideAccess once the player is authenticated to get the server side access code.

RequestServerSideAccess was giving me an error until I used the client_id with client_type: 3. Obtained from google-services.json from firebase. This is the web client id; the initial client id they give you is wrong.