google-signin-unity
google-signin-unity copied to clipboard
configuration is null!? Request not configured! Failing authenticate
if I login into Google sign-in first and sign out, and then sign in with other firebase auth method and then again come back and try to sign in to google sign in. It works. if I login into firebase Email and password and logout, and then try to sign in with google plugin, it gives this error. The Google Sign-in button greys out and app crashes. I will post my script and error both below. `#if UNITY_ANDROID || UNITY_IOS || UNITY_EDITOR using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Firebase; using Firebase.Auth; using Google; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using System.Text.RegularExpressions; using System.Collections;
public class Authentication : MonoBehaviour { public string webClientId = ""; [SerializeField] private string sceneToJump; [SerializeField] private string sceneToLoad;
public InputField emailInp; public InputField passwordInp; public InputField confirmPasswordInp; public Text warningInfo;
FirebaseAuth auth; FirebaseUser user; PhoneAuthProvider provider;
private string phoneId;
private GoogleSignInConfiguration configuration;
public GameObject VerificationPanel; public Text EmailConfirmationMessage; public Button SendEmailButton; public Button ResendEmailButton; public GameObject emailVerifyDoneCheck; public GameObject phoneVerifyDoneCheck; public Text warningEmailVerify;
public InputField countryCodeInp; public InputField phoneNumberInp; public InputField OTPInp; public Button sendOTPButton; public Button submitOTPButton; public Text warningPhoneVerify;
public Button VerificationDoneButton;
public const string MatchEmailPattern = @"^(([\w-]+.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@" + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9]).([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])." + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9]).([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|" + @"([a-zA-Z]+[\w-]+.)+[a-zA-Z]{2,4})$";
private void Awake() {
Debug.Log("Authentication_Stage1");
//CheckFirebaseDependencies();
Debug.Log("Authentication_Stage2: " + webClientId);
Initialize();
//configuration = new GoogleSignInConfiguration { WebClientId = webClientId, RequestEmail = true, RequestIdToken = true };
}
private void Initialize() { Debug.Log("Authentication_Stage3"); auth = FirebaseAuth.DefaultInstance; auth.StateChanged += AuthStateChanged; AuthStateChanged(this, null);
//auth = FirebaseAuth.DefaultInstance;
//auth.StateChanged += AuthStateChanged;
}
private void CheckFirebaseDependencies() { //FirebaseApp.CheckAndFixDependenciesAsync().ContinueWith(task => //{ // if (task.IsCompleted) // { // if (task.Result == DependencyStatus.Available) // auth = FirebaseAuth.DefaultInstance; // //auth.StateChanged += AuthStateChanged; // //auth.IdTokenChanged += IdTokenChanged; // else // AddToInformation("Could not resolve all Firebase dependencies: " + task.Result.ToString()); // } // else // { // AddToInformation("Dependency check was not completed. Error : " + task.Exception.Message); // } //}); }
public void SignInWithGoogle() { OnSignIn(); } public void SignOutFromGoogle() { OnSignOut(); }
public void SignInWithEmailAndPassword() { var email = emailInp.text; var password = passwordInp.text; bool emailRegExp = IsEmail(email); if (emailRegExp) { if (password.Length > 6) { SignInWithEmailAndPassword(email, password); warningInfo.text = "Everthing is perfect to SingIn"; } else { warningInfo.text = "Password should have atleast 6 characters!"; } } else { warningInfo.text = "Please enter valid Email address!"; }
} public void SignUpWithEmailAndPassword() { var email = emailInp.text; var password = passwordInp.text; var confirmPassword = confirmPasswordInp.text; bool emailRegExp = IsEmail(email); if (emailRegExp) { if (password.Length > 6) { if (password == confirmPassword) { SignUpWithEmailAndPassword(email, password); warningInfo.text = "Everthing is perfect to SignUp"; } else { warningInfo.text = "Password and confirm password does not match!"; }
}
else
{
warningInfo.text = "Password should have atleast 6 characters!";
}
}
else
{
warningInfo.text = "Please enter valid Email address!";
}
}
public static bool IsEmail(string email) { if (email != null) return Regex.IsMatch(email, MatchEmailPattern); else return false; } public void HidePasswordText() { passwordInp.contentType = InputField.ContentType.Password; confirmPasswordInp.contentType = InputField.ContentType.Password; passwordInp.ForceLabelUpdate(); confirmPasswordInp.ForceLabelUpdate(); } public void ShowPasswordText() { passwordInp.contentType = InputField.ContentType.Standard; confirmPasswordInp.contentType = InputField.ContentType.Standard; passwordInp.ForceLabelUpdate(); confirmPasswordInp.ForceLabelUpdate();
}
private void OnSignIn() { auth = FirebaseAuth.DefaultInstance; auth.StateChanged += AuthStateChanged;
GoogleSignIn.Configuration = new GoogleSignInConfiguration { WebClientId = webClientId, RequestEmail = true, RequestIdToken = true };
//GoogleSignIn.Configuration.UseGameSignIn = false;
//GoogleSignIn.Configuration.RequestIdToken = true;
Debug.Log("Calling SignIn");
Debug.Log("Authentication_Stage4");
//GoogleSignIn.Configuration.ForceTokenRefresh = true;
Debug.Log("Authentication_Stage4.1");
GoogleSignIn.DefaultInstance.SignIn().ContinueWith(OnAuthenticationFinished);
Debug.Log("Authentication_Stage4.2");
}
private void OnSignOut() { Debug.Log("Calling SignOut"); GoogleSignIn.DefaultInstance.SignOut(); FirebaseAuth.DefaultInstance.SignOut(); }
public void OnDisconnect() { Debug.Log("Calling Disconnect"); GoogleSignIn.DefaultInstance.Disconnect(); }
internal void OnAuthenticationFinished(Task<GoogleSignInUser> task) { Debug.Log("Authentication_Stage5");
if (task.IsFaulted)
{
using (IEnumerator<Exception> enumerator = task.Exception.InnerExceptions.GetEnumerator())
{
if (enumerator.MoveNext())
{
Debug.Log("Authentication_Stage5.1");
GoogleSignIn.SignInException error = (GoogleSignIn.SignInException)enumerator.Current;
Debug.Log("Got Error: " + error.Status + " " + error.Message);
Debug.Log("Authentication_Stage5.2");
}
else
{
Debug.Log("Got Unexpected Exception?!?" + task.Exception);
Debug.Log("Authentication_Stage6");
}
}
}
else if (task.IsCanceled)
{
Debug.Log("Canceled");
}
else
{
Debug.Log("Welcome: " + task.Result.DisplayName + "!");
Debug.Log("Email = " + task.Result.Email);
//AddToInformation("Google ID Token = " + task.Result.IdToken);
Debug.Log("Authentication_Stage7");
SignInWithGoogleOnFirebase(task.Result.IdToken);
}
}
private void SignInWithEmailAndPassword(string email, string password) { auth.StateChanged += AuthStateChanged; auth.SignInWithEmailAndPasswordAsync(email, password).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("SignInWithEmailAndPasswordAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("SignInWithEmailAndPasswordAsync encountered an error: " + task.Exception); return; }
user = task.Result;
Debug.LogFormat("User signed in successfully: {0} ({1}) ({2})",
user.DisplayName, user.UserId, user.IsEmailVerified);
//CheckUser();
});
}
private void SignUpWithEmailAndPassword(string email, string password) { auth.StateChanged += AuthStateChanged; auth.CreateUserWithEmailAndPasswordAsync(email, password).ContinueWith(task => { if (task.IsCanceled) { Debug.LogError("CreateUserWithEmailAndPasswordAsync was canceled."); return; } if (task.IsFaulted) { Debug.LogError("CreateUserWithEmailAndPasswordAsync encountered an error: " + task.Exception); return; }
// Firebase user has been created.
user = task.Result;
Debug.LogFormat("Firebase user created successfully: {0} ({1})",
user.DisplayName, user.UserId);
//CheckUser();
});
}
private void SignInWithGoogleOnFirebase(string idToken) { Credential credential = GoogleAuthProvider.GetCredential(idToken, null);
auth.StateChanged += AuthStateChanged;
Debug.Log("Authentication_Stage8");
auth.SignInWithCredentialAsync(credential).ContinueWith(task =>
{
AggregateException ex = task.Exception;
if (ex != null)
{
if (ex.InnerExceptions[0] is FirebaseException inner && (inner.ErrorCode != 0))
{
Debug.Log("Authentication_Stage9");
Debug.Log("\nError code = " + inner.ErrorCode + " Message = " + inner.Message);
}
}
else
{
Debug.Log("Sign in Successful.");
FirebaseUser newUser = task.Result;
Debug.Log("Authentication_Stage10");
Debug.LogFormat("User signed in successfully: {0} ({1}) Email verified?:{2}", newUser.DisplayName, newUser.UserId, newUser.IsEmailVerified);
}
});
}
public void SkipToLoggedIn() {
SceneManager.LoadScene(sceneToJump);
} private void AuthStateChanged(object sender, EventArgs eventArgs) { if (auth.CurrentUser != user) { bool signedIn = user != auth.CurrentUser && auth.CurrentUser != null; if (!signedIn && user != null) { Debug.Log("Signed out " + user.UserId); } user = auth.CurrentUser; if (signedIn) { Debug.Log("Checking Authetication in AuthStateChanged");
Debug.Log("Signed in " + user.UserId);
CheckUser();
}
}
}
void OnDestroy() { FirebaseAuth.DefaultInstance.StateChanged -= AuthStateChanged;
if (auth != null)
{
auth.StateChanged -= AuthStateChanged;
auth = null;
}
} }
Error: 05-04 04:58:02.293: I/Unity(8821): 05-04 04:58:02.293: I/Unity(8821): (Filename: ./Runtime/Export/Debug.bindings.h Line: 45) 05-04 04:58:02.295: E/native-googlesignin(8821): configuration is null!? 05-04 04:58:02.296: E/SignInFragment(8821): Request not configured! Failing authenticate 05-04 04:58:02.301: E/CRASH(8821): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
`
I'm having the same issue. Did you find a solution?
@jonathanahern this is work for me private void OnSignIn() {
if (GoogleSignIn.Configuration == null)
{
GoogleSignIn.Configuration = configuration;
GoogleSignIn.DefaultInstance = null;
}
Debug.Log("Calling SignIn Google");
try
{
GoogleSignIn.DefaultInstance.SignIn().ContinueWith(OnAuthenticationFinished);
}
catch (System.Exception ex)
{
Debug.LogError("Singin width google Exception:" + ex.Message);
}
}