Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Google Play Authentication

Discussion in 'Authentication' started by targaciej, Apr 12, 2022.

  1. targaciej

    targaciej

    Joined:
    Mar 22, 2014
    Posts:
    7
    Hello!

    Im trying to authenticate the user from Google Play.
    I’m using GooglePlayGamesPlugin-0.11.01.

    I used debug and production keys, tried web one nothing seems to work.

    With debug key I can login to Google, get player id, but when trying pass token to

    SignInWithGoogleAsync(string idToken) I get Request failed: 401, PERMISSION_DENIED.

    Are there any examples how to do it with 0.11.01?
    Thanks!
     
  2. EllieF_Unity

    EllieF_Unity

    Unity Technologies

    Joined:
    Nov 27, 2020
    Posts:
    39
    Hi there,

    You need to have a Game Server credential configured in addition to the Android credential so that you can send the token to a 3rd party server (Unity Authentication in this case). The Game Server credential should have a Web Application type OAuth client.

    Once you have the OAuth client configured, add the ID in the textbox I have highlighted on the GPGS Android Setup window:
    upload_2022-4-12_9-19-39.png
     
  3. targaciej

    targaciej

    Joined:
    Mar 22, 2014
    Posts:
    7
    Thank you for a reply!

    I have everything setup like that. Web id and successful connection. I get the token via PlayGamesPlatform.Instance.RequestServerSideAccess, and when I pass it to SignInWithGoogleAsync, i get 401 permission denied.
     
  4. EllieF_Unity

    EllieF_Unity

    Unity Technologies

    Joined:
    Nov 27, 2020
    Posts:
    39
    Could you share the snippet of code that you use when the player clicks to login with Google and then you pass the token to SignInWithGoogleAsync?
     
  5. targaciej

    targaciej

    Joined:
    Mar 22, 2014
    Posts:
    7
    Sure, I bet this is horrible ;)


    Code (CSharp):
    1. internal void ProcessAuthentication(SignInStatus status)
    2.         {
    3.             String c;
    4.             if (status == SignInStatus.Success)
    5.             {
    6.                 // Continue with Play Games Services
    7.                 //  print(PlayGamesPlatform.Instance.GetUserId());
    8.  
    9.                 PlayGamesPlatform.Instance.RequestServerSideAccess(
    10.    /* forceRefreshToken= */ false,
    11.                 code => {
    12.                     Debug.Log(c);
    13.                      SignInWithGoogleAsync(c);
    14.  
    15.                 });
    16.             }
    17.             else
    18.             {
    19.                 // Disable your integration with Play Games Services or show a login button
    20.                 // to ask users to sign-in. Clicking it should call
    21.                 // PlayGamesPlatform.Instance.ManuallyAuthenticate(ProcessAuthentication).
    22.                 print("no");
    23.             }
    24.         }
     
  6. EllieF_Unity

    EllieF_Unity

    Unity Technologies

    Joined:
    Nov 27, 2020
    Posts:
    39
    Thanks!

    Instead of using RequestServerSideAccess() could I ask you to try retrieving the id token from the local user instead. So, your code snippet should look like this:

    Code (CSharp):
    1.     internal void ProcessAuthentication(SignInStatus status)
    2.     {
    3.         String c;
    4.         if (status == SignInStatus.Success)
    5.         {
    6.             // Continue with Play Games Services
    7.             //  print(PlayGamesPlatform.Instance.GetUserId());
    8.  
    9.             c = ((PlayGamesLocalUser)PlayGamesPlatform.Instance.localUser).GetIdToken();
    10.             SignInWithGoogleAsync(c);
    11.  
    12.         }
    13.         else
    14.         {
    15.             // Disable your integration with Play Games Services or show a login button
    16.             // to ask users to sign-in. Clicking it should call
    17.             // PlayGamesPlatform.Instance.ManuallyAuthenticate(ProcessAuthentication).
    18.             print("no");
    19.         }
    20.     }
     
  7. EdwardAndy

    EdwardAndy

    Joined:
    Jul 26, 2020
    Posts:
    24
    I've got the same problem.The new version of GooglePlayGamesPlugin-0.11.01 seems like change methods a lot of it's api.There is no longer "GetIdToken()" method in class PlayGamesLocalUser.
    Is that means we can't get IDToken of Google Play sign-in any more, and unity authentication don't support GooglePlayGamesPlugin-0.11.01 yet.
    Or if we can use PlayGamesLocalUser.id instead of PlayGamesLocalUser.GetIdToken() to pass to SignInWithGoogleAsync(idToken)? I don't know.
     
  8. targaciej

    targaciej

    Joined:
    Mar 22, 2014
    Posts:
    7
    Yeah, this. There is no more GetIdToken in 0.11.01.
     
  9. EllieF_Unity

    EllieF_Unity

    Unity Technologies

    Joined:
    Nov 27, 2020
    Posts:
    39
    Ah, that is very true. I have v0.10.14 in my project currently and hadn't realised that the GetIdToken() function had been removed in v0.11.01. I will update my GPGS SDK and investigate. Please bear with me.
     
    DavidZobrist and EdwardAndy like this.
  10. EdwardAndy

    EdwardAndy

    Joined:
    Jul 26, 2020
    Posts:
    24
    OK, and thx for your response.
     
  11. EllieF_Unity

    EllieF_Unity

    Unity Technologies

    Joined:
    Nov 27, 2020
    Posts:
    39
    Hi,

    Thanks for waiting. Unfortunately, in the process of investigation I have actually found a bug. Currently, Unity Authentication is not compatible with the latest version of the Play Games Plugin for Unity as that version uses the new Play Games Services SDK and provides a different token in the response for RequestServerSideAccess(). The backend for Unity Authentication hasn't been updated to be able to handle the new token type just yet. I have reported the issue directly to the developers and I will make sure to provide an update whenever I get new information about the resolution of this issue.

    For the time being, I recommend downgrading to v0.10.14 in order to use these two services together. You can find the Unity package for that version here: https://github.com/playgameservices/play-games-plugin-for-unity/tree/v10.14/current-build
     
    grantar2k, ChHammad and EdwardAndy like this.
  12. EllieF_Unity

    EllieF_Unity

    Unity Technologies

    Joined:
    Nov 27, 2020
    Posts:
    39
    I can confirm that developers are currently investigating the issue.
     
  13. aaron4202

    aaron4202

    Joined:
    Apr 9, 2021
    Posts:
    2
    Been having issues for weeks, going to try downgrading. Hope this gets fixed soon
     
  14. EdwardAndy

    EdwardAndy

    Joined:
    Jul 26, 2020
    Posts:
    24
    That's all right. I'll downgrade temporary.
     
  15. DavidZobrist

    DavidZobrist

    Joined:
    Sep 3, 2017
    Posts:
    233
    @EllieF_Unity Any updates on supporting the current GooglePlayGamesPlugin?

    Support of the new token id / code that comes back from
    Code (CSharp):
    1. PlayGamesPlatform.Instance.RequestServerSideAccess()
     
  16. EllieF_Unity

    EllieF_Unity

    Unity Technologies

    Joined:
    Nov 27, 2020
    Posts:
    39
    Hi David,

    Unfortunately, I don't currently have any new updates. The developers are still working on resolving this issue and you should still use v0.10.14. However, it does seem that they are close to the resolution and will likely release a fix soon. I will make sure to post on this thread as soon as I know the fix has been released.
     
    kendrick_unity and DavidZobrist like this.
  17. don_crowell

    don_crowell

    Joined:
    Jun 16, 2022
    Posts:
    1
    Seeing same issue, Is there any updates to this?
     
  18. unity_Ctri

    unity_Ctri

    Unity Technologies

    Joined:
    Oct 20, 2020
    Posts:
    81
    I checked with the team, this is addressed in 2.1.0 of the Authentication SDK and is going through the release pipeline at the moment. Keep an eye out for updates!
     
    DavidZobrist likes this.
  19. kingzustin

    kingzustin

    Joined:
    Jan 16, 2018
    Posts:
    8
    mfakkaya and DavidZobrist like this.
  20. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    Hello has this been resolved?
     
  21. EllieF_Unity

    EllieF_Unity

    Unity Technologies

    Joined:
    Nov 27, 2020
    Posts:
    39
    Hi Prodigga,

    So sorry that it so long to get back to you. Yes, this was been resolved in version 2.1.0 of the Authentication SDK and which you can find in the Unity package manager. So, you can use the latest version of the GPGS Unity SDK with the latest version of the Authentication SDK.
     
    ilmario and Prodigga like this.
  22. helloroy

    helloroy

    Joined:
    Jun 23, 2016
    Posts:
    42
    Hello, I can't find the 2.1/2.2 version in package manager, only 2.0 there, I'm using Unity 2021.3.5f1

    Thanks
     
    Last edited: Sep 28, 2022
  23. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    482
    Manually import them via the package managers plus icon in the top left and typing com.unity.services.authentication and the version 2.2.0.

    It is well possible that they were not yet available and thus not detectable in that version.
     
  24. maxkcy

    maxkcy

    Joined:
    Oct 11, 2021
    Posts:
    62
    I still seem to be getting the same issues with authentication 2.2.0 plugin v0.11.01
     
    Last edited: Oct 16, 2022
    gferrari likes this.
  25. Julian-Unity3D

    Julian-Unity3D

    Unity Technologies

    Joined:
    Apr 28, 2022
    Posts:
    192
    Hey all,
    I'm taking over on this thread.
    Can you confirm that you have indeed updated to Authentication 2.2.0 and Google Play Games Plugin for Unity 0.11.01.

    I've just built a fresh project added the plugin and package, built to an android phone, and check my logcat, everything is working as is.

    It also looks like you need to set up your plugin.

    Take a look at this page for further assistance: Set up a Google Play Games sign-in (unity.com)
     
    Last edited: Oct 21, 2022
  26. maxkcy

    maxkcy

    Joined:
    Oct 11, 2021
    Posts:
    62
    I was able to sign in with Google Play Games Services the first time. But how do I stop automatic autherization on app start up after it has been signed in once. Edit: I found out that the devs for the GPGS plugin removed the SignOut(); method. After signing in once, it will automatically sign in everytime the user opens up the app. Appearently, the app user can go into settings and sign themselves out, this is why, so I tried this, and I couldn't find a way even with the instructions on how to sign out.
    Second, how can I log-in with regular Google log-in if my app is not a game, or if my app is for desktop or web versions, because getting the Session Token is only possible with the plug-in, that works only on android. Furthermore, I was unable to sign in with just Google on android even, while using the Unity docs guide for logging in with just google. I was given an invalid request error. 401. Even though I was able to sign in with Google Play Games. Edit: since I could not sign out of GPGS, I can't test the above.


    Here is my script:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Unity.Services.Core;
    5. using Unity.Services.Authentication;
    6. using System.Threading.Tasks;
    7. using UnityEngine.UI;
    8. using TMPro;
    9.  
    10. using GooglePlayGames;
    11. using GooglePlayGames.BasicApi;
    12. public class LoginManager : MonoBehaviour
    13. {
    14.     [SerializeField] private GameObject _loggedInPanel;
    15.     [SerializeField] private TextMeshProUGUI _statText;
    16.     // Bottom Panel Buttons
    17.     [SerializeField] private GameObject _signInLastChachedUserBtn;
    18.     [SerializeField] private GameObject _clearCachedUserBtn;
    19.     [SerializeField] private GameObject _signOutBtn;
    20.     [SerializeField] private GameObject _showStatusBtn;
    21.     private bool _isShowingPanel;
    22.     private string _service = "";
    23.     private string _triedService = "";
    24.     void Awake()
    25.     {
    26.         _statText.text = "No log-in events registered... " + "\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\nx\n";
    27.         _loggedInPanel.SetActive(false);
    28.         _isShowingPanel = false;
    29.     }
    30.     // async Start()
    31.     async void Start()
    32.     {
    33.         #region InitializingUnityServices
    34.         // UnityServices.InitializeAsync() will initialize all services that are subscribed to Core.
    35.         await UnityServices.InitializeAsync();
    36.         Debug.Log(UnityServices.State);
    37.         // (optional) set up events
    38.         SetupEvents();
    39.         #endregion
    40.     }
    41.     #region Setup/Register authentication events
    42.     // Setup authentication event handlers if desired
    43.     void SetupEvents()
    44.     {
    45.         AuthenticationService.Instance.SignedIn += () =>
    46.         {
    47.             // Shows how to get a playerID
    48.             Debug.Log($"PlayerID: {AuthenticationService.Instance.PlayerId}");
    49.  
    50.             // Shows how to get an access token
    51.             Debug.Log($"Access Token: {AuthenticationService.Instance.AccessToken}");
    52.             _signOutBtn.SetActive(true);
    53.  
    54.         };
    55.  
    56.         AuthenticationService.Instance.SignInFailed += (err) =>
    57.         {
    58.             Debug.LogError(err);
    59.         };
    60.  
    61.         AuthenticationService.Instance.SignedOut += () =>
    62.         {
    63.             Debug.Log("Player signed out.");
    64.             _signOutBtn.SetActive(false);
    65.         };
    66.  
    67.         AuthenticationService.Instance.Expired += () =>
    68.         {
    69.             Debug.Log("Player session could not be refreshed and expired.");
    70.         };
    71.     }
    72.     #endregion
    73.     #region SignInAnonymouslyAsync
    74.     public async void SignInAnon()
    75.     {
    76.         // set service
    77.         _triedService = "Anonymous Log-In";
    78.         await SignInAnonymouslyAsync();
    79.     }
    80.     async Task SignInAnonymouslyAsync()
    81.     {
    82.         try
    83.         {
    84.             await AuthenticationService.Instance.SignInAnonymouslyAsync();
    85.             Debug.Log("Sign in anonymously succeeded!");
    86.  
    87.             // Shows how to get the playerID
    88.             Debug.Log($"PlayerID: {AuthenticationService.Instance.PlayerId}");
    89.  
    90.             // Set Logged In panel Active and change status
    91.          
    92.             OnSuccessfulLogIn(out _service, _triedService);
    93.         }
    94.         catch (AuthenticationException ex)
    95.         {
    96.             // Compare error code to AuthenticationErrorCodes
    97.             // Notify the player with the proper error message
    98.             Debug.LogException(ex);
    99.             OnUnsuccessfulLogIn(ex.ToString(), _triedService);
    100.         }
    101.         catch (RequestFailedException ex)
    102.         {
    103.             // Compare error code to CommonErrorCodes
    104.             // Notify the player with the proper error message
    105.             Debug.LogException(ex);
    106.             OnUnsuccessfulLogIn(ex.ToString(), _triedService);
    107.         }
    108.     }
    109.     #endregion
    110.     #region SignInGPGS
    111.     public string TokenGPGS;
    112.     public string ErrorGPGS;
    113.     public void LoginGPGSManually()
    114.     {
    115.         // set service
    116.         _triedService = "Google Play Games";
    117.         LoginGooglePlayGames();
    118.     }
    119.     private void LoginGooglePlayGames()
    120.     {
    121.         // Initialize next line under PlayGamesPlatform from within Awake
    122.         PlayGamesPlatform.Activate();
    123.         // PlayGamesPlatform.Instance.Authenticate((success) =>
    124.         PlayGamesPlatform.Instance.ManuallyAuthenticate((success) =>
    125.         {
    126.             if (success == SignInStatus.Success)
    127.             {
    128.                 Debug.Log("Login with Google Play games successful.");
    129.  
    130.                 PlayGamesPlatform.Instance.RequestServerSideAccess(true, async code =>
    131.                 {
    132.                     Debug.Log("Authorization code: " + code);
    133.                     TokenGPGS = code;
    134.                     // This token serves as an example to be used for SignInWithGooglePlayGames
    135.                     await SignInWithGooglePlayGamesAsync(TokenGPGS);
    136.                 });
    137.             }
    138.             else if (success == SignInStatus.Canceled)
    139.             {
    140.                 ErrorGPGS = "Failed to retrieve Google play games authorization code due to Sign-In Cancelation";
    141.                 Debug.Log("Login Unsuccessful Due to Sign-In Cancelation");
    142.                 OnUnsuccessfulLogIn(ErrorGPGS, _triedService);
    143.             }
    144.             else
    145.             {
    146.                 ErrorGPGS = "Failed to retrieve Google play games authorization code due to Internal Error";
    147.                 Debug.Log("Login Unsuccessful Due to Internal Error");
    148.                 OnUnsuccessfulLogIn(ErrorGPGS, _triedService);
    149.             }
    150.         });
    151.     }
    152.  
    153.     async Task SignInWithGooglePlayGamesAsync(string authCode)
    154.     {
    155.         try
    156.         {
    157.             await AuthenticationService.Instance.SignInWithGooglePlayGamesAsync(authCode);
    158.             Debug.Log("SignIn is successful.");
    159.             OnSuccessfulLogIn(out _service, _triedService);
    160.         }
    161.         catch (AuthenticationException ex)
    162.         {
    163.             // Compare error code to AuthenticationErrorCodes
    164.             // Notify the player with the proper error message
    165.             Debug.LogException(ex);
    166.             OnUnsuccessfulLogIn(ex.ToString(), _triedService);
    167.         }
    168.         catch (RequestFailedException ex)
    169.         {
    170.             // Compare error code to CommonErrorCodes
    171.             // Notify the player with the proper error message
    172.             Debug.LogException(ex);
    173.             OnUnsuccessfulLogIn(ex.ToString(), _triedService);
    174.         }
    175.     }
    176.     #endregion
    177.  
    178.     public string TokenGoogle;
    179.     public string ErrorGoogle;
    180.     public void LoginGoogleManually()
    181.     {
    182.         _triedService = "Google";
    183.         LoginGooglePlayGamesForGoogle();
    184.     }
    185.  
    186.     private void LoginGooglePlayGamesForGoogle()
    187.     {
    188.         // Initialize next line under PlayGamesPlatform from within Awake
    189.         PlayGamesPlatform.Activate();
    190.         // PlayGamesPlatform.Instance.Authenticate((success) =>
    191.         PlayGamesPlatform.Instance.ManuallyAuthenticate((success) =>
    192.         {
    193.             if (success == SignInStatus.Success)
    194.             {
    195.                 Debug.Log("Login with Google Play games for Google successful.");
    196.  
    197.                 PlayGamesPlatform.Instance.RequestServerSideAccess(true, async code =>
    198.                 {
    199.                     Debug.Log("Authorization code: " + code);
    200.                     TokenGoogle = code;
    201.                     // This token serves as an example to be used for SignInWithGooglePlayGames
    202.                     await SignInWithGoogleAsync(TokenGoogle);
    203.                 });
    204.             }
    205.             else if (success == SignInStatus.Canceled)
    206.             {
    207.                 ErrorGoogle = "Failed to retrieve Google play games for Google authorization code due to Sign-In Cancelation";
    208.                 Debug.Log("Login Unsuccessful Due to Sign-In Cancelation");
    209.                 OnUnsuccessfulLogIn(ErrorGoogle, _triedService);
    210.             }
    211.             else
    212.             {
    213.                 ErrorGoogle = "Failed to retrieve Google play games for Google authorization code due to Internal Error";
    214.                 Debug.Log("Login Unsuccessful Due to Internal Error");
    215.                 OnUnsuccessfulLogIn(ErrorGoogle, _triedService);
    216.             }
    217.         });
    218.     }
    219.     async Task SignInWithGoogleAsync(string idToken)
    220.     {
    221.         try
    222.         {
    223.             await AuthenticationService.Instance.SignInWithGoogleAsync(idToken);
    224.             Debug.Log("SignIn is successful.");
    225.             OnSuccessfulLogIn(out _service, _triedService);
    226.         }
    227.         catch (AuthenticationException ex)
    228.         {
    229.             // Compare error code to AuthenticationErrorCodes
    230.             // Notify the player with the proper error message
    231.             Debug.LogException(ex);
    232.             OnUnsuccessfulLogIn(ex.ToString(), _triedService);
    233.         }
    234.         catch (RequestFailedException ex)
    235.         {
    236.             // Compare error code to CommonErrorCodes
    237.             // Notify the player with the proper error message
    238.             OnUnsuccessfulLogIn(ex.ToString(), _triedService);
    239.             Debug.LogException(ex);
    240.         }
    241.     }
    242.  
    243.  
    244.  
    245.  
    246.  
    247.  
    248.  
    249.  
    250.  
    251.  
    252.     private void OnSuccessfulLogIn(out string _service, string triedservice)
    253.     {
    254.         _loggedInPanel.SetActive(true);
    255.         _isShowingPanel = true;
    256.         _showStatusBtn.GetComponentInChildren<TextMeshProUGUI>().text = "Hide Status Panel";
    257.         _service = triedservice;
    258.         _statText.text = $"Status: Logged-In with {triedservice}\n";
    259.         _statText.color = Color.green;
    260.         _signOutBtn.SetActive(true);
    261.     }
    262.     private void OnUnsuccessfulLogIn(string ex, string triedservice)
    263.     {
    264.         _loggedInPanel.SetActive(true);
    265.         _isShowingPanel = true;
    266.         if (_statText.text.Contains("No log-in events registered..."))
    267.         {
    268.             _statText.text = "";
    269.         }
    270.         _statText.text += $"\nStatus: Unable to log into {triedservice}\n";
    271.         _statText.text += $"Error:\n{ex}\n";
    272.         _showStatusBtn.GetComponentInChildren<TextMeshProUGUI>().text = "Hide Status Panel";
    273.         _statText.color = Color.red;
    274.     }
    275.     public void SignOutOfServices()
    276.     {
    277.         if (!AuthenticationService.Instance.IsSignedIn) return;
    278.         if (PlayGamesPlatform.Instance.IsAuthenticated())
    279.         {
    280.             // Todo:
    281.         }
    282.         _statText.text = $"Status: Logged out of {_service}\n";
    283.         _statText.color = Color.white;
    284.         AuthenticationService.Instance.SignOut();
    285.         Debug.Log("Signed Out");
    286.         _signOutBtn.SetActive(false);
    287.     }
    288.     public void ClearCachedUser()
    289.     {
    290.         if (AuthenticationService.Instance.SessionTokenExists)
    291.         {
    292.             AuthenticationService.Instance.ClearSessionToken();
    293.         }
    294.     }
    295.  
    296.     public void ShowStatus()
    297.     {
    298.         if (_isShowingPanel)
    299.         {
    300.             _loggedInPanel.SetActive(false);
    301.             _isShowingPanel = false;
    302.             _showStatusBtn.GetComponentInChildren<TextMeshProUGUI>().text = "Show Status Panel";
    303.         }
    304.         else
    305.         {
    306.             _loggedInPanel.SetActive(true);
    307.             _isShowingPanel = true;
    308.             _showStatusBtn.GetComponentInChildren<TextMeshProUGUI>().text = "Hide Status Panel";
    309.         }
    310.     }
    311.  
    312.     public void SignInCachedUserManually()
    313.     {
    314.         if (!_service.Contains("Cached"))
    315.         {
    316.             _triedService = _service + " as Cached User";
    317.         }
    318.         else
    319.         {
    320.             _triedService = _service;
    321.         }
    322.         SignInCachedUser();
    323.     }
    324.     async void SignInCachedUser()
    325.     {
    326.         // Check if a cached user already exists by checking if the session token exists
    327.         if (!AuthenticationService.Instance.SessionTokenExists)
    328.         {
    329.             // if not, then do nothing
    330.             OnUnsuccessfulLogIn("Error: No previous logged-in session token exists", "Cached User Sign-In");
    331.             return;
    332.         }
    333.  
    334.         // Sign in Anonymously
    335.         // This call will sign in the cached user.
    336.         try
    337.         {
    338.             await AuthenticationService.Instance.SignInAnonymouslyAsync();
    339.             Debug.Log("Sign in anonymously succeeded!");
    340.  
    341.             // Shows how to get the playerID
    342.             Debug.Log($"PlayerID: {AuthenticationService.Instance.PlayerId}");
    343.             OnSuccessfulLogIn(out _service, _triedService);
    344.         }
    345.         catch (AuthenticationException ex)
    346.         {
    347.             // Compare error code to AuthenticationErrorCodes
    348.             // Notify the player with the proper error message
    349.             Debug.LogException(ex);
    350.             OnUnsuccessfulLogIn(ex.ToString(), _service);
    351.         }
    352.         catch (RequestFailedException ex)
    353.         {
    354.             // Compare error code to CommonErrorCodes
    355.             // Notify the player with the proper error message
    356.             Debug.LogException(ex);
    357.             OnUnsuccessfulLogIn(ex.ToString(), _service);
    358.         }
    359.     }
    360. }
     
    Last edited: Oct 26, 2022
    3DGamesDeveloper and Prodigga like this.
  27. dev_duong_nguyenanh

    dev_duong_nguyenanh

    Joined:
    Oct 12, 2022
    Posts:
    2
    I am facing same issue
    Im using Authentication 2.2.0 and Google Play Games Plugin for Unity 0.11.01.
    Please help me with that
     
  28. Holmes555

    Holmes555

    Joined:
    Sep 22, 2016
    Posts:
    14
    Could you also help with understanding difference between Google sign in option with using Google Play Games plugin for Unity v10.14 and below which uses Play Games Services v1 SDK (description here) vs GooglePlayGames sign in option with using Google Play Games plugin for Unity v11.01 and above which recommends using Play Games Services v2 SDK (description here).

    Because for me it seems like Unity just took two versions of the same library and named them differently. First it was just Google Play Games sign in (which actually they renamed to just Google) and the usage was the same as now in Google. I implemeted that old Google sign in with Authentication service - 1.0.0-pre.37 and it worked as Google Play Games and now they making it as Google sign in.

    My main question is: what's changed or is it the same approach but using different versions of Google Play Games plugin for compatibility? Should I move to the newest one and the functioning would be the same?

    P.S. My old version Google Play Games plugin started to failed on build because of:
    Assets\AssetStore\GooglePlayGames\OurUtils\PlatformUtils.cs(34,39): error CS0246:
    The type or namespace name 'AndroidJavaObject' could not be found (are you missing a using directive or an assembly reference?)
    or
    Assets\AssetStore\GooglePlayGames\OurUtils\PlatformUtils.cs(33,30): error CS0246:
    The type or namespace name 'AndroidJavaClass' could not be found (are you missing a using directive or an assembly reference?)
     
  29. Julian-Unity3D

    Julian-Unity3D

    Unity Technologies

    Joined:
    Apr 28, 2022
    Posts:
    192
    We are aware of an issue within the documentation and are working on a fix.

    We're aware of this issue between the two and are working on it.
     
    maxkcy likes this.
  30. Overmobile

    Overmobile

    Joined:
    Aug 3, 2017
    Posts:
    1
    Only now there is no idToken, but there is AuthCode and these are different entities. Now it is not possible to get the same identifier. How to make it all compatible is now not clear.
     
  31. Julian-Unity3D

    Julian-Unity3D

    Unity Technologies

    Joined:
    Apr 28, 2022
    Posts:
    192
    Hello all,

    Just a quick update, I and a few members on my team have been actively working on this issue with Google play sign in and google sign in with Authentication.
    We've solved one part of it but are still stumbling on a few parts.

    Just to clarify, Authentication works fine, it's google's API we are trying to clarify as it's ever changing.

    I will share here what I find out over the next week.

    Thanks for your patience on this I too am trying to get this working on my own personal projects.
     
    ilmario and Prodigga like this.
  32. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    Thanks for you want your teams hard work, and thanks for the updates!
     
  33. john79

    john79

    Joined:
    Jul 13, 2016
    Posts:
    16
    hello there, how are you doing ?
    i'm still have this issue since 5 days and is becoming very stressfull. I'm wondering why google team made this connection, authentication and setup of leaderboards etc so complicated.
    please take look at the google sitekit component for wordpress, this is an interesting way to integrate feature to a platform. rather then copy and past sha1 and using shell with the key tool. this is very annoying for an end user.

    this playgames sdk must be tied up with unity services and with few clicks able to set up all necessary. this is what i'm expecting with the version 3 and must be done very quickly. Playgames are around since long time and i'm so disappointed to come and see that google developers implement a such complicated plugin.

    i hope and wish in a ver 3 done in the right way.

    salut
     
    socialtrens, N1ghtrunner and northman like this.
  34. northman

    northman

    Joined:
    Feb 28, 2008
    Posts:
    144
    I got the same issue.
    I was following the Google Play Game Services document and then following the Unity Authentication document, but my Android App still could not sigin to GPGS.
    The debug information just till "Social.localUser.Authenticate(OnGooglePlayGamesLogin);" or "PlayGamesPlatform.Instance.Authenticate(success =>". It means after call the authenticate function the app never get result.

    I use Unity 2022.1.22f1 and try on both Google Plugins such as 0.10.14 and 0.11.01.

    I found in Google Play Console Pre-launch report, an crashes and ANRs occured:

    ANR
    errorErrorbrightness_1 Issue 1 of 1 brightness_ 1 Detected on 1 device during testing
    Stack trace:

    ANR in com.google.android.apps.messaging;PID: 13731;Broadcast of Intent { act=android.accounts.LOGIN_ACCOUNTS_CHANGED flg=0x5000010 cmp=com.google.android.apps.messaging/com.google.apps.tiktok.account.data.device.DeviceAccountsChangedReceiver_Receiver };

    I don't know is it reasonable for my Unity Android auto sigin failed.
     
    Last edited: Dec 6, 2022
  35. bernhardt12

    bernhardt12

    Joined:
    Dec 17, 2020
    Posts:
    4
    Can someone point to the documentation that outlines the "need to have a Game Server credential configured in addition to the Android credential so that you can send the token to a 3rd party server (Unity Authentication in this case)".

    I'm able to log in to GPGS, but I'm not able to link that sign in to my Unity AuthenticationService. I've combed through the documentation and only found a reference to needing the Game Server credential configured in this thread...
     
  36. Cytanic

    Cytanic

    Joined:
    Jun 6, 2019
    Posts:
    5
    hi everyone , here the awnser that work in me , this is mi code to autenticate

    public void LoginGooglePlayGames()
    {
    PlayGamesPlatform.Instance.Authenticate((success) =>
    {
    if (success == SignInStatus.Success)
    {
    Debug.Log("Login with Google Play games successful.");

    PlayGamesPlatform.Instance.RequestServerSideAccess(true, code =>
    {
    Debug.Log("Authorization code: " + code);

    // This token serves as an example to be used for SignInWithGooglePlayGames
    });
    }
    else
    {

    Debug.Log("Login Unsuccessful");
    }
    });
    }
    private void Awake()
    {
    PlayGamesPlatform.Activate();
    LoginGooglePlayGames();
    }
    after this just see the video , this work for me

     
  37. N1ghtrunner

    N1ghtrunner

    Joined:
    Jan 5, 2015
    Posts:
    104
    This integration is such an absolute dog show. I have also been struggling for DAYS to get this to work with no success. I honestly at this stage feel like I'm going around in circles and am at the point of abandoning Unity.

    1. Why is a Web App Client ID required?
    2. Where does one get a Web App Client ID? Google Play Games plugin says generate in the Developer Console (really? Why?)
    3. Why does the Unity documentation and Google Play Games plugin documentation only refer to this in the most vague manner?
    4. Why does the Unity documentation for setting up a Google Play Game sign-in not note that the Authentication package needs to be installed?
    5. Will all of this work WITHOUT needing a project setup on the Developer Console? (how do I get the Web App Client ID if this doesnt work, which Unity says I need to have?)
    6. In Player Settings, what needs to be ticked in order for this bollocks to work? Release/Debug/Custom Proguard? Why?
    7. Why does it NOT work when building to local device but sign-in (only) DOES work when downloading from internal test track?
    8. Why does the Unity documentation refer to "Google Play Services" while the Authentication package refers to "Google Play Games" - is this a legitimate difference, or just another outdated unity page??
    9. Are updates to Google Play Games required from the Android SDK and/or what version of the JDK is required, if these were both installed WITH Unity. It's not clear.

    The problem with a lot of the above is you could go on your own adventure to sort this out, as many of us are, and just dig a the hole even deeper by breaking something else.

    The last time I released a mobile game using Google Play was in November 2020, and back then it was a disaster to get this integration working. It's hard to believe that in TWO YEARS it only seems to have gotten more complicated, more unclear and more unreliable. Unity is a big company and a lot of people are going to be wanting to deploy to mobile, but these are the hoops we have to waste time with because there is NO CLARITY on a) what you really need b) what isn't supported right now or any of the above 8 items. I appreciate that maybe you do have answers to these items but they are very hard to find (I have been looking guys). This really needs to get better please. You're not an indie company - you're a listed corporate. Get someone to figure this out, and write a comprehensive, up-to-date document that covers everything you need, every minimum version, every path variable, all the unsupported stuff etc. for a given Unity project. Please!
     
  38. AusAdam

    AusAdam

    Joined:
    Jan 2, 2021
    Posts:
    47
    100% agree, The fact there are no simple examples is crazy. Did you happen to get it working with a php backend or has anyone got the php backend code....all I want is the players google play id on my server.....why is this so hard....
     
    acgabor, sampenguin, ArtemVy and 3 others like this.
  39. john79

    john79

    Joined:
    Jul 13, 2016
    Posts:
    16
    I completely agree with you...but they build a document, a check list with 30 point to setup and install. Those google developers they are so smart, so smart that setting up a route for a Boing 747 is easier.
    I spent 3 months playing with play games rather then build the game. I published the app bundle probably 40 times to understand how the F*** it was working. you should be ashamed and not mad for my comment.

    I attached the screen shot of another mystery around google playgamens. every two days the all setting of my game disappear. do you have any idea? does it happen to you as well?

    What about the many version around they all work completely different. another mistake of the team leader of those project.
     

    Attached Files:

  40. Julian-Unity3D

    Julian-Unity3D

    Unity Technologies

    Joined:
    Apr 28, 2022
    Posts:
    192
    Hey everyone,

    We're aware of the issues surrounding the confusing documentation, some of which comes from google directly.
    It is something that is actively being worked on and improved and once we have a solid working answer I will get back here and share it straight away.

    I too also want to get it working on my personal project.
     
  41. SF_FrankvHoof

    SF_FrankvHoof

    Joined:
    Apr 1, 2022
    Posts:
    780
    Here's the doc I made for myself:
    Running through this should get anyone up & running.
    (Blacked out parts are only relevant for my custom wrapper for GPG).
    GPG-docs.png
    Proguard-file should include:
    Code (CSharp):
    1. -keep class com.google.android.gms.games.leaderboard.** { *; }
    2. -keep class com.google.android.gms.games.snapshot.** { *; }
    3. -keep class com.google.android.gms.games.achievement.** { *; }
    4. -keep class com.google.android.gms.games.event.** { *; }
    5. -keep class com.google.android.gms.games.stats.** { *; }
    6. -keep class com.google.android.gms.games.* { *; }
    7. -keep class com.google.android.gms.common.api.ResultCallback { *; }
    8. -keep class com.google.android.gms.signin.** { *; }
    9. -keep class com.google.android.gms.dynamic.** { *; }
    10. -keep class com.google.android.gms.dynamite.** { *; }
    11. -keep class com.google.android.gms.tasks.** { *; }
    12. -keep class com.google.android.gms.security.** { *; }
    13. -keep class com.google.android.gms.base.** { *; }
    14. -keep class com.google.android.gms.actions.** { *; }
    15. -keep class com.google.games.bridge.** { *; }
    16. -keep class com.google.android.gms.common.ConnectionResult { *; }
    17. -keep class com.google.android.gms.common.GooglePlayServicesUtil { *; }
    18. -keep class com.google.android.gms.common.api.** { *; }
    19. -keep class com.google.android.gms.common.data.DataBufferUtils { *; }
    20. -keep class com.google.android.gms.nearby.** { *; }
     
  42. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    Thanks for sharing this wealth of knowledge! But god damn...

    "I want to authenticate a user with my back end"

    "Ok, you might want to sit down for this..."
     
  43. AusAdam

    AusAdam

    Joined:
    Jan 2, 2021
    Posts:
    47
    I sort of got mine working while working with the google dev help people. You can request an IDToken not a AuthToken but you also need to require the useremail. Then on the backend you can store the useremail and authenticate them that way....I know its not the best way to do it but the ID that google gives you is not the google play id but rather their google id I think.....and the google dev said that some people could spoof it so it's best not to use it.....Therefore using the email is the only way i have found so far.
     
  44. SF_FrankvHoof

    SF_FrankvHoof

    Joined:
    Apr 1, 2022
    Posts:
    780
    The docs by Google are okay, once you've gone through the process once.
    There's just a lot of pitfalls that can mess with new users. (such as everything failing in Debug-Builds unless you disable 'Enable Anti-Piracy').
     
    sampenguin and Prodigga like this.
  45. Julian-Unity3D

    Julian-Unity3D

    Unity Technologies

    Joined:
    Apr 28, 2022
    Posts:
    192
    Thanks for this, I'll give this a run through myself.

    Can anyone confirm if they are struggling with:
    SignInWithGooglePlayGamesAsync

    or
    LinkWithGooglePlayGamesAsync


    If you have it working with both of these, can you share your solutions as this will greatly help us improve our documentation.
     
  46. john79

    john79

    Joined:
    Jul 13, 2016
    Posts:
    16
    Hello Julian, thank you for your response. As a software architect with four years of experience in Unity, I wanted to share my thoughts on the use of interfaces by the Google development team. In my opinion, their decision to use interfaces instead of just an API call has caused significant challenges for users of the Google Play service.

    In my experience, a microservice architecture would have been the better choice for this kind of project. Microservices allow for more modular and independent components, which can make it easier to scale and maintain a system. For example, in WCF, the WSDL was used to describe the class used via the API, which was not only sufficient, but also the best choice for the good of everyone, including developers and producers.

    While interfaces can be a useful tool in certain contexts, they are not always the best choice, and should be evaluated carefully in the context of the specific project requirements. In this case, it seems that a microservice architecture may have been a better fit for the Google Play service.

    http://endavid.com/index.php?entry=97
    It seems that the user struggled with implementing a certain functionality on Android using Unity due to a bad software architectural choice. The implementation of the IAchievements and IAchievementsDescription interfaces on the client-side was a poor design decision, which resulted in a painful implementation process for the user. Instead, the implementation should have been done on the server-side, with a simple and secure API call made in plain C# to retrieve the required items from the server.

    To address this issue, a solution proposed is to refactor the Google Play Game Service class and adopt a Model-Driven Design approach. A simple Game Service API Client for Unity in C# should be implemented, which can be used across different platforms. The microservice architecture should be behind the API, and the user should interact with a few simple CRUD methods to retrieve the required data. This approach would simplify the implementation process for the user and improve the overall software architecture.
     
    Last edited: Feb 20, 2023
    AusAdam likes this.
  47. nicholas_2411

    nicholas_2411

    Joined:
    Jan 22, 2019
    Posts:
    3
    Any Updates on this matter ?
     
  48. Julian-Unity3D

    Julian-Unity3D

    Unity Technologies

    Joined:
    Apr 28, 2022
    Posts:
    192
    Hi all,

    Quick update.

    I appreciate all the feedback you are giving me on this thread and on other threads.

    A new support document is currently being worked on to help make using Authentication with Google Play Games easier. It will likely be shared as a pinned thread on the forums, and will be added to these threads.
    However, please bare with us while we iron out some kinks.
     
    Last edited: Mar 1, 2023
  49. AusAdam

    AusAdam

    Joined:
    Jan 2, 2021
    Posts:
    47
    Thats great, Can you also include the backend example files as well especially for us using php!
     
  50. TheKingNuro

    TheKingNuro

    Joined:
    Nov 13, 2021
    Posts:
    5
    Any idea when this could be? I'm quite new when it comes to developing android games. I would like to have a solid base before I dive deeper into building the game. Especially since I use cloud save, I want to set up the save system.

    After some debugging the playplatform authenticate returns Success it's just the code not returning the token.
     
    Last edited: Mar 2, 2023