Search Unity

Question Setup Google OAuth Login in Unity

Discussion in 'Authentication' started by Nichathan, Jan 30, 2023.

  1. Nichathan

    Nichathan

    Joined:
    Mar 8, 2020
    Posts:
    23
    I tried to follow the tutorial from Unity

    I imported GooglePlayGamesPlugin-0.11.01.unitypackage and then, I added the GooglePlayGamesExampleScript, I added Play Games Services configuration resources to my game, I used the client ID from my web application credentials, then I tried again with the client ID from my android credentials, I created a keystore to identify the project and I created an aab build for my project which displays the results in a text box on the screen.

    I created a new app on the Google Play Console, created a Play Games Services configuration and set up achievements.

    I created Google Cloud OAuth 2.0 Client ID's for a Web Application and Android Application using my package name and SHA1 fingerprint

    I receive no errors and everything resolved well but I do get 42 logs from my Assets\ExternalDependencyManager\

    Does anyone know what I may be doing wrong with authenticating with Google Play?

    Code (CSharp):
    1.  
    2. using GooglePlayGames;
    3. using GooglePlayGames.BasicApi;
    4. using System.Collections;
    5. using System.Collections.Generic;
    6. using UnityEngine;
    7.  
    8. public class GPGSManager : MonoBehaviour
    9. {
    10.     [SerializeField] TMPro.TMP_Text content;
    11.     public string Token;
    12.     public string Error;
    13.  
    14.  
    15.     // Start is called before the first frame update
    16.     void Start()
    17.     {
    18.         content.text = "Start\n";
    19.  
    20.         PlayGamesPlatform.Activate();
    21.         PlayGamesPlatform.Instance.Authenticate((success)=>
    22.         {
    23.             content.text += "finished\n"+ success.ToString()+"\n";
    24.  
    25.             if (success == SignInStatus.Success)
    26.             {
    27.                 Debug.Log("Login with Google Play games successful.");
    28.                 content.text += "Login with Google Play games successful.";
    29.  
    30.                 PlayGamesPlatform.Instance.RequestServerSideAccess(true, code =>
    31.                 {
    32.                     Debug.Log("Authorization code: " + code);
    33.                     content.text += "Authorization code: " + code;
    34.                     Token = code;
    35.                     // This token serves as an example to be used for SignInWithGooglePlayGames
    36.                 });
    37.             }
    38.             else
    39.             {
    40.                 Error = "Failed to retrieve Google play games authorization code";
    41.                 Debug.Log("Login Unsuccessful");
    42.                 content.text += "Login Unsuccessful";
    43.             }
    44.         });
    45.     }
    46. }
    47.  
     
  2. Nichathan

    Nichathan

    Joined:
    Mar 8, 2020
    Posts:
    23
    So, it turns out that you cannot activate Google Play while editing. You must build and run your game on a cellular device with an android operating system installed. This means that debugging is completely useless so you will need to create an onscreen text box to debug that way with a 5 minute wait time between runs. At least you do not need to publish your app on the Google Play console for this to work.
     
  3. Nichathan

    Nichathan

    Joined:
    Mar 8, 2020
    Posts:
    23
    Edit, I was wrong. While I can authenticate with Google, I still cannot use
    Code (CSharp):
    1. PlayGamesPlatform.Instance.RequestServerSideAccess(true, code =>
    2.                 {
    3.                     Debug.Log("Authorization code: " + code);
    4.                     content.text += "Authorization code: " + code;
    5.                     Token = code;
    6.                     // This token serves as an example to be used for SignInWithGooglePlayGames
    7.                 });
    Because nothing details how to set up the web client ID or in what order to share the multiple auto generated credential SHA1's created
     
  4. AusAdam

    AusAdam

    Joined:
    Jan 2, 2021
    Posts:
    62
    Let me know how you go with this, I can get the auth code but then no idea how to get the google play id from it on the php side of things.
     
  5. Julian-Unity3D

    Julian-Unity3D

    Unity Technologies

    Joined:
    Apr 28, 2022
    Posts:
    192
    Hey, we actually have an ongoing discussion on this thread about google play sign in. One user so far as a work around for the time being.

    I suggest you keep your discussion in your current open thread so that we don't get lost with what's happening.

    But basically we are working on improving the documentation.
     
  6. angelofdev

    angelofdev

    Joined:
    Jul 1, 2018
    Posts:
    1
    Any progress on this? Updating the engine from 2019.3.3f1 to any of the current stable releases on my project has been an absolute S*** show for Google Play Services and Google Ads on Unity.