首页 > 解决方案 > 凭据无效 - Unity Firebase

问题描述

过去两年我一直在使用 Unity 开发应用程序,直到现在才意识到我的手机身份验证无法正常工作。这是因为我在 Android 上进行开发,因此我一直只看到“verificationCompleted”的结果,而不是 codeSent。

换句话说,手动输入短信代码是行不通的。它说凭据无效。它不是!代码是对的。问题是,我将我的代码复制到另一个项目,然后它完美地工作。因此,我的代码可能没有问题。这里可能发生了什么?此外,一切正常,直到我应该验证代码本身。我收到了短信之类的。

当代码没有错误时,您何时会收到错误、无效的凭据?感觉什么都试过了!

提前感谢您的帮助!

这也是我的代码的一些图片。有些东西与身份验证无关,但是...


    public void VerifyPhoneNumber(string _phoneNumber)
    {
        Debug.Log(String.Format("Auth is {0}, AuthenticationController is {1} and GameController is {2}.", auth, authenticationController, null));

        

        var phoneAuthProvider = Firebase.Auth.PhoneAuthProvider.GetInstance(auth);
        phoneAuthProvider.VerifyPhoneNumber(_phoneNumber, phoneAuthTimeoutMs, null,
            verificationCompleted: (cred) =>
            {
                Debug.Log("Verification Completed");

                MutualUiController.mutualUI.loadingPanel.gameObject.SetActive(false);

                auth.SignInWithCredentialAsync(cred).ContinueWith(HandleSignInResult);
            },
            verificationFailed: (error) =>
            {
                Debug.Log("Verification Failed" + error);
            },
            codeSent: (id, token) =>
            {
                Debug.Log("Verification Code Sent");

                phoneAuthVerificationId = id;
                

                Debug.Log("ID: " + id + ", Token: " + token.ToString());

                if (SceneController.currentScene == Scene.AuthenticationPage)
                {
                    MutualUiController.mutualUI.loadingPanel.gameObject.SetActive(false);

                    Transform panel = GameObject.Find("AuthPageUI").GetComponent<AuthPageUI>().verificationPanel;
                    panel.gameObject.SetActive(true);
                }
            },
            codeAutoRetrievalTimeOut: (id) =>
            {
                Debug.Log("Code Auto Timeout");
            });
    }

    //verificationCompleted: (cred) =>
    //        {
    //            //Debug.Log("Verification Completed");

    //            //MutualUiController.mutualUI.loadingPanel.gameObject.SetActive(false);

    //            //auth.SignInWithCredentialAsync(cred).ContinueWith(HandleSignInResult);
    //        },

    public void VerifyRecievedPhoneCode(string recievedCodeInput)
    {
        var phoneAuthProvider = Firebase.Auth.PhoneAuthProvider.GetInstance(auth);
        var cred = phoneAuthProvider.GetCredential(phoneAuthVerificationId, recievedCodeInput);

        auth.SignInWithCredentialAsync(cred).ContinueWith(HandleSignInResult);
    }

标签: firebaseunity3dauthenticationsmscredentials

解决方案


推荐阅读