Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Social.localUser.Authenticate always returns false #2425

Closed
tucsok007 opened this issue Jan 22, 2019 · 5 comments
Closed

Social.localUser.Authenticate always returns false #2425

tucsok007 opened this issue Jan 22, 2019 · 5 comments

Comments

@tucsok007
Copy link

Hi,

I'm facing an issue with authentication: Social.localUser.Authenitcate always returns false. My signing keys are matching. I have my email added as a tester. The project is still in test mode so it's not published. I am trying to test on android. I was wondering if anyone could help me to resolve this, please?

`

    void Start() {
    if (ab == null)
    {
        chars = new List<Character>();
        ab = this;

        DontDestroyOnLoad(this);
        loadingtext = GameObject.FindGameObjectWithTag("Loadtext");
        setLoadingText("Loading Assets...", false);
    }
    else if (ab != this)
    {
        Debug.LogError("AssetBundleManager init failed.");
        Destroy(gameObject);
        return;
    }

    if (Application.isEditor) this.editor = true;

    if(isEditor)
    {
        textures = AssetBundle.LoadFromFile(Application.persistentDataPath + "/AB/textures");
        if (textures == null)
        {
            setLoadingText("AssetBundle textures error", true);
            return;
        }

        gameobjects = AssetBundle.LoadFromFile(Application.persistentDataPath + "/AB/gameobjects");
        if (gameobjects == null)
        {
            setLoadingText("AssetBundle gameobjects error", true);
            return;
        }
    }
    else
    {
        textures = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/textures");
        if (textures == null)
        {
            setLoadingText("AssetBundle textures error", true);
            return;
        }

        gameobjects = AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/gameobjects");
        if (gameobjects == null)
        {
            setLoadingText("AssetBundle gameobjects error", true);
            return;
        }
    }
    
    LoadAllCharacters();
    doneLoad = true;

    if(isEditor)
    {
        doneGooglePlayInit = true;
        return;
    }

    StartCoroutine(SignIn());

    //doneGooglePlayInit = true;
}

private IEnumerator SignIn()
{
    bool donesignin = false;

    setLoadingText("Signing in to Google Play...", false);

    PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().RequestServerAuthCode(false).Build();
    PlayGamesPlatform.InitializeInstance(config);
    PlayGamesPlatform.Activate();

    Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;

    if (!Social.localUser.authenticated)
    {
        Social.localUser.Authenticate(success => {
            if (!success)
            {
                setLoadingText("Failed to sign in to Google Play services!", true);
                StopCoroutine(SignIn());
                return;
            }
            else
            {
                setLoadingText("Google Play sign in success!", false);
                donesignin = true;
            }
        });
    }
    else
    {
        setLoadingText("Already signed in to Google Play.", false);
        donesignin = true;
    }

    yield return new WaitUntil(() => donesignin == true);

    setLoadingText("Authenticating to Firebase...", false);

    string auth_code = PlayGamesPlatform.Instance.GetServerAuthCode();
    if (string.IsNullOrEmpty(auth_code))
    {
        setLoadingText("Failed to get server auth code!", true);
        StopCoroutine(SignIn());
    }

    setLoadingText("Server authentication succcessful.", false);
    Debug.LogFormat("Google Play auth code is: {0}", auth_code);

    Firebase.Auth.Credential creds = Firebase.Auth.PlayGamesAuthProvider.GetCredential(auth_code);

    auth.SignInWithCredentialAsync(creds).ContinueWith(task =>
    {
        if (task.IsCanceled)
        {
            setLoadingText("Sign in cancelled.", true);
            StopCoroutine(SignIn());
            return;
        }
        if (task.IsFaulted)
        {
            setLoadingText("Sign in error: " + task.Exception, true);
            StopCoroutine(SignIn());
            return;
        }

        Firebase.Auth.FirebaseUser firebaseUser = task.Result;
        setLoadingText("Firebase sign in successful", false);
        Debug.LogFormat("Firebase sign in success: {0} (UUID: {1})", firebaseUser.DisplayName, firebaseUser.UserId);
        doneGooglePlayInit = true;
    });

    yield return null;
}`
@tucsok007
Copy link
Author

Unity version in case if it's needed: 2018.3.0f2.

@legas1
Copy link
Contributor

legas1 commented Jan 22, 2019

    PlayGamesClientConfiguration config = new 
    PlayGamesClientConfiguration.Builder().RequestServerAuthCode(false).Build();
    PlayGamesPlatform.InitializeInstance(config);
    PlayGamesPlatform.Activate();

This should be called only once and also without logs I cannot say what the problem is, but try to move this piece of code to Awake or Start method.

@tucsok007
Copy link
Author

I'll try to do it with logs but the SignIn coroutine is called from the start method. I needed to do it this way beacuse otherwise firebase authentication would start before google play sign in is finished as it's a lambda expression.

@tucsok007
Copy link
Author

    PlayGamesClientConfiguration config = new 
    PlayGamesClientConfiguration.Builder().RequestServerAuthCode(false).Build();
    PlayGamesPlatform.InitializeInstance(config);
    PlayGamesPlatform.Activate();

This should be called only once and also without logs I cannot say what the problem is, but try to move this piece of code to Awake or Start method.

I get DEBUG: Starting Auth Transition. Op: SIGN_IN status: ERROR_NOT_AUTHORIZED

@tucsok007
Copy link
Author

I solved the issue. The problem was that I tried debugging using the original apk and I didn't knew that google resigns the apk. After downloading the deprived version and installing that on my device everything was working fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants