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

Resolved Authenticating with Google Play services cancelling immediately

Discussion in 'Authentication' started by Noxirus, Mar 24, 2022.

  1. Noxirus

    Noxirus

    Joined:
    Sep 18, 2019
    Posts:
    40
    Hello Everyone,

    I have been working on getting google play services to work with my android application and having this weird issue. Whenever I attempt to authenticate a black bar flashes across the screen vertically and then I get a debug message of "Authentication Cancelled" (Thats the message variable that gets returned), not sure what would be causing it to cancel immediately.

    public bool Authenticate()
    {
    bool a = false;
    DebugInterface.GetInstance().AddConsoleLog("Starting to Authenticate");

    PlayGamesPlatform.Instance.Authenticate((success, message) =>
    {
    DebugInterface.GetInstance().AddConsoleLog(message);
    if (success)
    {
    AuthenticationSuccessful();
    }
    else
    {
    StartCoroutine(WaitForAuthenticationCoroutine());
    }
    });

    return a;
    }

    My initial thoughts are that security on my phone is preventing the app from logging in (albeit it not actually informing me of any security issues).

    I have been patching the game onto my phone using the unity builder as well.

    If anyone has any ideas as to why authentication would be cancelling immediately would be appreciated.

    -Noxirus
     
  2. randyl_unity

    randyl_unity

    Unity Technologies

    Joined:
    Aug 22, 2019
    Posts:
    7
    Hi!

    One thing I see with the code you shared is that it looks like it seems like this may not be used in a blocking fashion, which may lead to some odd behavior. You could try this, where we explicitly block on the returned result.

    Code (CSharp):
    1. public static async Task<ScenarioResult> Test()
    2.         {
    3.             await UnityServices.InitializeAsync();
    4.  
    5.             InitializePlayGamesLogin();
    6.  
    7.             // Test anonymous + linking code snippets
    8.             await AuthenticationService.Instance.SignInAnonymouslyAsync();
    9.             await LinkWithGoogleAsync();
    10.  
    11.             // Test sign-in code snippet.
    12.             AuthenticationService.Instance.SignOut();
    13.             await SignInWithGoogleAsync();
    14.  
    15.             return ScenarioResult.Success;
    16.         }
    17.  
    18.         static void InitializePlayGamesLogin()
    19.         {
    20.             var config = new PlayGamesClientConfiguration.Builder()
    21.                 // Requests an ID token be generated.
    22.                 // This OAuth token can be used to
    23.                 // identify the player to other services such as Firebase.
    24.                 .RequestIdToken()
    25.                 .Build();
    26.  
    27.             PlayGamesPlatform.InitializeInstance(config);
    28.             PlayGamesPlatform.DebugLogEnabled = true;
    29.             PlayGamesPlatform.Activate();
    30.         }
    31.  
    32.         static Task<string> GetGooglePlayGamesIdToken()
    33.         {
    34.             var tcs = new TaskCompletionSource<string>();
    35.             Social.localUser.Authenticate((success) =>
    36.             {
    37.                 if (success)
    38.                 {
    39.                     tcs.SetResult(((PlayGamesLocalUser)Social.localUser).GetIdToken());
    40.                 }
    41.                 else
    42.                 {
    43.                     tcs.SetException(new Exception("Retrieving GooglePlayGames IdToken failed."));
    44.                 }
    45.             });
    46.  
    47.             return tcs.Task;
    48.         }
    49.  
    50.         static async Task SignInWithGoogleAsync()
    51.         {
    52.             var idToken = await GetGooglePlayGamesIdToken();
    53.             await AuthenticationService.Instance.SignInWithGoogleAsync(idToken);
    54.         }
    55.  
    56.         static async Task LinkWithGoogleAsync()
    57.         {
    58.             var idToken = await GetGooglePlayGamesIdToken();
    59.             await AuthenticationService.Instance.LinkWithGoogleAsync(idToken);
    60.         }
    61.  
    If there are additional problems, it may be best to check in with Google's support forums.
     
    Holmes555 and unity_Ctri like this.
  3. Noxirus

    Noxirus

    Joined:
    Sep 18, 2019
    Posts:
    40
    Thanks so much! We actually figured out what the issue was. For testing google auth services for Google Play your account needs to be added to the list of authorized testers, after adding my google play games account to the authorized testers list I was able to properly authenticate.

    -Noxirus
     
    Recon03 likes this.
  4. jdayanami

    jdayanami

    Joined:
    Apr 27, 2018
    Posts:
    1
    Nice man, where did you add the email as tester? Same problem here, cancelled on awake script.
     
  5. a_strl

    a_strl

    Joined:
    Aug 12, 2019
    Posts:
    7
     

    Attached Files:

    ViktorTuzovSilverfox likes this.