Authenticating with Google Play services cancelling immediately

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

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.

public static async Task<ScenarioResult> Test()
        {
            await UnityServices.InitializeAsync();

            InitializePlayGamesLogin();

            // Test anonymous + linking code snippets
            await AuthenticationService.Instance.SignInAnonymouslyAsync();
            await LinkWithGoogleAsync();

            // Test sign-in code snippet.
            AuthenticationService.Instance.SignOut();
            await SignInWithGoogleAsync();

            return ScenarioResult.Success;
        }

        static void InitializePlayGamesLogin()
        {
            var config = new PlayGamesClientConfiguration.Builder()
                // Requests an ID token be generated.
                // This OAuth token can be used to
                // identify the player to other services such as Firebase.
                .RequestIdToken()
                .Build();

            PlayGamesPlatform.InitializeInstance(config);
            PlayGamesPlatform.DebugLogEnabled = true;
            PlayGamesPlatform.Activate();
        }

        static Task<string> GetGooglePlayGamesIdToken()
        {
            var tcs = new TaskCompletionSource<string>();
            Social.localUser.Authenticate((success) =>
            {
                if (success)
                {
                    tcs.SetResult(((PlayGamesLocalUser)Social.localUser).GetIdToken());
                }
                else
                {
                    tcs.SetException(new Exception("Retrieving GooglePlayGames IdToken failed."));
                }
            });

            return tcs.Task;
        }

        static async Task SignInWithGoogleAsync()
        {
            var idToken = await GetGooglePlayGamesIdToken();
            await AuthenticationService.Instance.SignInWithGoogleAsync(idToken);
        }

        static async Task LinkWithGoogleAsync()
        {
            var idToken = await GetGooglePlayGamesIdToken();
            await AuthenticationService.Instance.LinkWithGoogleAsync(idToken);
        }

If there are additional problems, it may be best to check in with Google’s support forums.

2 Likes

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

2 Likes

Nice man, where did you add the email as tester? Same problem here, cancelled on awake script.

9328376--1305590--Screenshot 2023-09-16 070433.png

1 Like