unity googleSignIn with Firebase DeveloperError 'Google.GoogleSignIn+SignInException'

1k Views Asked by At

EDIT: Was able to fix it The problem was the key. I have uploaded my app to google console and used their sha1 key under app integrity.

Im new to Unity and Firebase/GoogleSignIn.
-trying to setup google signin button over firebase in unity.
-using unity 2021.3.6f1, build for android 6+, scripting backend: IL2CPP, apiCompatibilityLevelPerPlatform: .Net Standard 2.1, target architecture: ARMv7 & ARM64, not a development build, Firebase project settings Prod-Tag is NOT production

My steps:
-created unity firebase project with packagename from playersettings
-downloaded google-services.json and added to asset folder
-downloaded (firebase unity sdk 9.3.0) FirebaseAuth.unitypackage and google-signin-plugin-1.0.4.unitypackage and imported both into unity (skipped parse on google signin plugin, deleted net 3.5 unity.tasks.dll & unity.compat.dll from parse firebaseauth)
-enabled authentification -> sign in methode -> google (Web-Client-ID matches from google-services.json)
-generated keystore with keystore manager on unity (puplishing settings), read out the SHA-256 fingerprint with java keytool and added to firebase project settings.
-have used the WebClient ID OAuth client id type 3 from google-services.json
-build the app and installed on phone and throwing the following error:

DeveloperError Exception of type 'Google.GoogleSignIn+SignInException' was thrown.

My code:

using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using Firebase;
using Firebase.Auth;
using Firebase.Extensions;
using Google;
using System.Net.Http;


public class FirebaseGoogleLogin : MonoBehaviour
{
    public Text warning;
    public Animator anWarning;
    private bool fireBaseReady;


    private GoogleSignInConfiguration configuration;
    Firebase.DependencyStatus dependencyStatus = Firebase.DependencyStatus.UnavailableOther;
    Firebase.Auth.FirebaseAuth auth;
    Firebase.Auth.FirebaseUser user;

    void Awake()
    {
        configuration = new GoogleSignInConfiguration
        {
            WebClientId = "XXX from google-services.json",
            RequestIdToken = true
        };
    }

    private void Start()
    {
        auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
    }

    public void OnSignIn()
    {
        GoogleSignIn.Configuration = configuration;
        GoogleSignIn.Configuration.UseGameSignIn = false;
        GoogleSignIn.Configuration.RequestIdToken = true;
        GoogleSignIn.Configuration.RequestEmail = true;

        user = auth.CurrentUser;
        if (user != null)
        {
            warning.text = "User signed in successfully:" + user.Email + " " + user.UserId;
            anWarning.Play("Base Layer.FontButtonFadeLong", 0, 0);
        }
        else
        {
            GoogleSignIn.DefaultInstance.SignIn().ContinueWith(OnAuthenticationFinished);
        }
    }

    internal void OnAuthenticationFinished(Task<GoogleSignInUser> task) 
    {
        //TaskCompletionSource<FirebaseUser> signInCompleted = new TaskCompletionSource<FirebaseUser>();
        //signIn.ContinueWith(task => { 
            if (task.IsCanceled)
            {
                warning.text = "1:" + task.Exception;
                anWarning.Play("Base Layer.FontButtonFadeLong", 0, 0);
            }
            else if (task.IsFaulted)   //ERROR OCCURS HERE
            {
                using (IEnumerator<System.Exception> enumerator =
               task.Exception.InnerExceptions.GetEnumerator())
                {
                    if (enumerator.MoveNext())
                    {
                        GoogleSignIn.SignInException error =
                                (GoogleSignIn.SignInException)enumerator.Current;
                        warning.text = "Got Error: " + error.Status + " " + error.Message;
                        anWarning.Play("Base Layer.FontButtonFadeLong", 0, 0);
                    }
                    else
                    {
                    warning.text = "Got Unexpected Exception?!?" + task.Exception;
                    anWarning.Play("Base Layer.FontButtonFadeLong", 0, 0);
                    }
                }
            }
            else
            {
                warning.text = "3";
                anWarning.Play("Base Layer.FontButtonFadeLong", 0, 0);
                Credential credential = Firebase.Auth.GoogleAuthProvider.GetCredential(((Task<GoogleSignInUser>)task).Result.IdToken, null);
                auth.SignInWithCredentialAsync(credential).ContinueWith(authTask => {
                    if (authTask.IsCanceled)
                    {
                        warning.text = "auth task canceled:" + authTask.Exception;
                        anWarning.Play("Base Layer.FontButtonFadeLong", 0, 0);
                    }
                    else if (authTask.IsFaulted)
                    {
                        warning.text = "auth task is faulted:" + authTask.Exception;
                        anWarning.Play("Base Layer.FontButtonFadeLong", 0, 0);
                    }
                    else
                    {
                        warning.text = "User signed in successfully:";
                        anWarning.Play("Base Layer.FontButtonFadeLong", 0, 0);
                    }
                });
            }
       // });
    }
}

OnSignIn is started by button press.
Error occurs at 'internal void OnAuthenticationFinished(Task<GoogleSignInUser> task)' -> '(task.IsFaulted)'
I have no console errors/build errors in unity beside in the FirebaseGoogleLogin.cs script:

Error CS0433: The type 'Task' exists in both 'Unity.Tasks, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' and 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=XXX' Assembly-CSharp, Assembly-CSharp.Player

but people say its common and there shouldnt be any problem.

Please after tons of hours working on this, can anyone tell me whats the error i have made ?

1

There are 1 best solutions below

0
Codemaker2015 On

This might be because of wrong SHA1 key or release.keystore file.

Follow the below steps to resolve the issue.

  • Open Publishing settings in Player settings and click on Keystore manager to generate a release keystore. enter image description here
  • Go to the folder where the keystore is located and open a terminal.
  • Run the keytool utility provided with Java to get the SHA-1 fingerprint of the certificate. You should get both the release and debug certificate fingerprints.
  • To get the release certificate fingerprint:
keytool -list -v -alias <your-key-name> -keystore <path-to-production-keystore>
  • To use google auth, you need to provide some additional information to finish setting up your project. Create a project in the Google console and specify your package name (Eg: com.google.samples.quickstart.signin) when prompted. You will also need to provide the SHA-1 hash of your signing certificate.

https://developers.google.com/identity/sign-in/android/start enter image description here enter image description here

Demo project repository link: https://github.com/codemaker2015/google-signin-unity3d-demo

For more: