Sign In Register

How can we help you today?

Start a new topic

GPGS unity plugin NONAUTHENTICATED when logging in to gamesparks

 Hi, I have a problem with authenticating user in gamesparks which already connected to google play game services. I'm using Unity 5.4.1f and gpgs unity plugin  9.35. GooglePlayConnectRequest is returning proper code but user is not authenticated. I double checked credentials in gamesparks console and in unity and evverything seems to be ok.

GooglePlayGames.PlayGamesPlatform.Instance.GetServerAuthCode((status, code) => 
        {          
        new GooglePlayConnectRequest()
            .SetCode(code)
            .SetRedirectUri("http://www.gamesparks.com/oauth2callback")
            .SetDisplayName(displayName)
            .SetErrorOnSwitch(true)
            .Send(
            response =>
            {
                Debug.Log("AUTH CODE " + code);
                if (String.IsNullOrEmpty(User.LocalUser.GooglePlayId))
                {
                    new AddGooglePlayIdToUserRequest().Send(delegate (User user)
                    {
                        User.LocalUser.GooglePlayId = user.GooglePlayId;
                        if (successCallback != null)
                        {
                            successCallback();
                        }
                    }, () =>
                    {
                        Debug.LogError("AddGooglePlayIdToUserRequest failed");
                        if (failCallback != null)
                        {
                            failCallback();
                        }
                    });
                }
                else if (successCallback != null)
                {
                    successCallback();
                }
            },
            response =>
            {
                Debug.LogError("GooglePlayConnectRequest failed " + response.Errors.JSON);
                if (failCallback != null)
                {
                    failCallback();
                }
            });
        });

 

This is the log fom the app:

 

11-16 16:30:11.370: I/Unity(1604): GS: SEND:{"@class":".AuthenticatedConnectRequest","hmac":"C3sG3f4U0SMtpZpEmBCaqEwN6FHc3j45iM7jHTe7Z0w=","os":"ANDROID","platform":"Android","deviceId":"64878c5ab1d462db4fa440fd9e320a0d","authToken":"0e1688cc-532c-4147-ba0e-052190ea3932","sessionId":"0c53c54b-4e12-4290-aa61-684475f51943"}

11-16 16:30:11.570: I/Unity(1604): GS: RECV:{"@class":".AuthenticatedConnectResponse","authToken":"91cb067d-1d13-4521-b617-14d05f3670ff","requestId":"0","sessionId":"0c53c54b-4e12-4290-aa61-684475f51943","userId":"57f7689c6677888b21f4d5c2"}

11-16 16:30:11.580: I/Unity(1604): GS: SEND:{"@class":".GooglePlayConnectRequest","code":"4/shoe8z4twHP8L7MhpI6OoinHLozKa3biRgqzKbBZXjs","redirectUri":"http://www.gamesparks.com/oauth2callback","displayName":"Qbul3kZ","errorOnSwitch":true,"requestId":"636149106115656200_11"}

11-16 16:30:11.960: I/Unity(1604): GS: RECV:{"@class":".AuthenticationResponse","error":{"code":"NOTAUTHENTICATED"},"newPlayer":false,"requestId":"636149106115656200_11"}

 

Am I missing something?


Anybody, enything?

Hi Jakub,


Would you be able to explain your sign in process in a bit more detail? Is your player authenticated with GS prior to you Authenticating with Google? Has this particular google account previously been linked as a social account with a GS player account? What you might try is a Device Authentication first then a Google Authentication.


Kind regards,

 - Steve

First I need to connect with GS using device authentication in order to get player progress. Then I authenticate with google ( Social.localuser.Authenticate() ). I get a popup confirming that everything is ok and then I try to authenticate with GS using google credentials. 

Hi Jakob,


Your previous log message seems to indicated that no device authentication is taking place prior to your google authentication? An AuthenticatedConnectRequest/Response is the initial setup of the web socket for the Client and not a device Authentication. 


Hope this helps,

 - Steve

I did not put any logs, because I thought it was irrelevant. I succesfuly pass deviceauthentication:

 

11-21 16:30:20.656: I/Unity(17645): GS: SEND:{"@class":".DeviceAuthenticationRequest","deviceId":"64878c5ab1d462db4fa440fd9e320a0d","deviceOS":"ANDROID","deviceType":"Handheld","operatingSystem":"Android","requestId":"636153426206546680_0"}
11-21 16:30:20.856: I/Unity(17645): GS: RECV:{"@class":".AuthenticationResponse","authToken":"4f0cf3e1-66ce-4aa1-be6a-c999aa91d7c7","displayName":"Megathenes Zuyderwyk","newPlayer":false,"requestId":"636153426206546680_0","userId":"57f7689c6677888b21f4d5c2"}

 Later I login to gpgs. And after succesful login to gpgs I try to login to GS which results in NONAUTHENTICATED response.

Well I do authenticate with GS using device Authentication at the very start of the game. Then I connect with google play. And when both are succesful I try to login to GS using GooglePlayConnectRequest and I end up with NONAUTHENTICATED  user.

When I launch the app, at the very start I connect to GS with device authentication which is successful. Later I connect to gpgs and I get a popup that loging in is complete. When both logings are ok I try to login to GS using googlePlay auth code which results in NONAUTHENTICATED response.

Hi Jakub,


If possible I'd like to get a little more information from you:


- After your DeviceAuthentication, are you able to log events/requests successfully prior to sending your GooglePlayConnectRequest?

- How are you obtaining the acess code & redirect uri you are supplying to the request?


Regards,

Vinnie


Yes I am able to log events/requests successfully.


I downgraded gpgs to 0.9.34.

In android plugins folder I have:

play-services-auth-9.8.0

play-services-auth-base-9.8.0

play-services-base-9.8.0

play-services-basement-9.8.0

play-services-games-9.8.0

play-services-gcm-9.8.0

play-services-iid-9.8.0

play-services-nearby-9.8.0

play-services-tasks-9.8.0

support-annotations-23.4.0

support-v4-24.0.0


GS sdk version 5.4.0rc85


I login to google play successfuly using this code: 

 public void AuthenticateGameService()
    {
        Debug.Log("Play Games platform Initialize.");
#if UNITY_ANDROID
        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
        PlayGamesPlatform.InitializeInstance(config);
        PlayGamesPlatform.DebugLogEnabled = true;
        PlayGamesPlatform.Activate();
        PlayGamesPlatform.Instance.Authenticate(OnAuthenticated);
#else
        Debug.LogError("GPGS not supported on this platform!");
#endif
    }

#if UNITY_ANDROID
    public void OnAuthenticated(bool success)
    {
        Debug.Log("Play Games platform Authenticate. IsSuccess?: " + success.ToString());

        if (success)
        {
            Debug.Log("Requesting AuthCode:");
            PlayGamesPlatform.Instance.GetServerAuthCode(OnServerAuthCodeRetrieved);
        }
    }

    void OnServerAuthCodeRetrieved(CommonStatusCodes statusCode, string authCode)
    {
        Debug.Log(string.Format("statusCode: {0}", statusCode));
        Debug.Log(string.Format("authCode: {0}", authCode));
        this.authCode = authCode;
        LoginToGamesparks();
    }
#endif

    private void LoginToGamesparks()
    {
        if (currentPlatform == SocialPlatform.GooglePlayGameServices)
        {
#if UNITY_ANDROID
            Debug.Log("LoginToGamesparks GPGS");
            BackendServices.instance.GooglePlayConnect(authCode,OnGamesparksLoginSucces, OnGamesparksLoginFailed);
#else
        Debug.LogError("GPGS not supported on this platform!");
#endif
        }
        if (currentPlatform == SocialPlatform.GameCenter)
        {
            Debug.Log("LoginToGamesparks GC");
            BackendServices.instance.GameCenterConnect(OnGamesparksLoginSucces, OnGamesparksLoginFailed);
        }
    }

 

GS LOGIN: 

 

public void GooglePlayConnect(string code, Action successCallback, Action failCallback = null)
    {
        string accessToken = GooglePlayGames.PlayGamesPlatform.Instance.GetAccessToken();
        string displayName = GooglePlayGames.PlayGamesPlatform.Instance.GetUserDisplayName();
        Debug.Log("ACCESS TOKEN " + accessToken);
                
        new GooglePlayConnectRequest(GS.Instance)
            .SetCode(code)
            .SetRedirectUri("http://www.gamesparks.com/oauth2callback")
            .SetDisplayName(displayName)
            .SetErrorOnSwitch(true)
            .Send(
            response =>
            {
                Debug.Log("AUTH CODE " + code);
                if (String.IsNullOrEmpty(User.LocalUser.GooglePlayId))
                {
                    new AddGooglePlayIdToUserRequest().Send(delegate (User user)
                    {
                        User.LocalUser.GooglePlayId = user.GooglePlayId;
                        if (successCallback != null)
                        {
                            successCallback();
                        }
                    }, () =>
                    {
                        Debug.LogError("AddGooglePlayIdToUserRequest failed");
                        if (failCallback != null)
                        {
                            failCallback();
                        }
                    });
                }
                else if (successCallback != null)
                {
                    successCallback();
                }
            },
            response =>
            {
                Debug.LogError("GooglePlayConnectRequest failed " + response.Errors.JSON);
                if (failCallback != null)
                {
                    Debug.Log(response.ScriptData.JSON);
                    failCallback();
                }
            });
        
    }

 

I still get NONAUTHENTICATED response.

 

11-24 10:02:15.244: I/Unity(5646): GS: SEND:{"@class":".GooglePlayConnectRequest","code":"4/eyio0xIAnikVgdMgYZMYAvEA5sRDCyZqe62KAfTTVaM","redirectUri":"http://www.gamesparks.com/oauth2callback","displayName":"Qbul3kZ","errorOnSwitch":true,"requestId":"636155785352438070_31"}

 

11-24 10:02:18.494: I/Unity(5646): GS: RECV:{"@class":".AuthenticationResponse","error":{"code":"NOTAUTHENTICATED"},"newPlayer":false,"requestId":"636155785352438070_31"}

Hi Jakub,


I have created a ticket for this issue to ensure we can resolve this for you as soon as possible.


Thanks,


Oisín

Hi Jakub,


Somehow your last comment got caught in our spam filter and we just saw it, apologies.


We are looking into this and will reply to you shortly.


Thanks,


Oisín

Hi Jakub,

 

Thanks for the additional information. We can rule out that it is an actual authentication issue from our end, and conclude that it is something to do with the GooglePlay request.

 

Just want to double check a few things as there are quite a few steps in setting this process up.

 

-Have you set the Client ID and Client Secret properly?

-Have you tested this outside of the Unity Editor (on a device)? (There have been issues with testing GPS functions in the Unity Editor).

-The redirectUri provided should match the address provided as your callback url when setting up your app with Google. We don't perform any validation on the redirectUri, we just send it on to Google along with the code. Google, however, do check this address, and if it doesn't match the callback url previously defined your code will not be validated.

-Is your Google App ID set up correctly?

 

-Pádraig

Hi. Gamesparks.


I'm getting exactly the same issue with Google Play. Is there any update on this issue?


Thanks 

Daniel

Hi Daniel,


There are quite a few potential causes for this issue. Can you confirm for me that you were successfully able to authenticate with Google Play through your app (i.e. you successfully obtained an authCode & username using the Google Play plugin)?


If this is the case here are some of the prime candidates for the source of the problem:


- Sending the request with a null/empty authCode - try logging the code prior to sending to ensure it is being obtained properly. If this is  the problem try switching from GetAccessToken()/GetIdToken() to GetServerAuthCode().

- Sending the obtained authCode in the 'accessToken' field of the GooglePlayConnectRequest (it should be set to the 'code' field)

- The 'redirectUri' submitted with your GooglePlayConnectRequest not matching that specified when setting up your game in the GooglePlayDeveloperConsole. The correct redirecturi to use can be found on the credential page for your linked Web App under 'Authorised Redirect URIs'.

- Not having the 'Enable Google Plus API Access' box ticked in your Unity Android Setup.

- Having either the 'Web App Client ID' in Unity or the 'Google Application Client ID' in the GameSparks Google Integration set to the ID of your linked Android App rather than your linked Web App.

- Having the 'Google Appl ID' not match the ID of your Google Play game (found under the name of your game on the Google Play Developer Console, and also as the 'Application ID' of your linked Android app).


Any of these scenarios will lead to an invalid request or failure in communications between GameSparks and Google Play, which could result in the error you are experiencing. 


Let me know if any of these pointers led you to the source of the problem.


Regards,

Vinnie



Login to post a comment