Skip to content

[Question] Phone Authentication on Android causes an error: "VerifyPhoneNumber: builder faild to create PhoneAuhtOptions" #764

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

Closed
Hasan-OG opened this issue Jun 20, 2023 · 3 comments

Comments

@Hasan-OG
Copy link

Hasan-OG commented Jun 20, 2023

  • Unity editor version: 2020.3.45f1
  • Firebase Unity SDK version: 11.0.0
  • Source you installed the SDK: .unitypackage
  • Problematic Firebase Component: Auth
  • Other Firebase Components in use: Analytics, Crashlytics, RemoteConfig, Database, Storage
  • Additional SDKs you are using: None
  • Platform you are using the Unity editor on: Windows
  • Platform you are targeting: Android
  • Scripting Runtime: IL2CPP
  • Pre-built SDK from the website or open-source from this repo: None

Hi, I have a question regarding Phone Authentication on Android.

We have 5 Android games, each one has its own Firebase application configured in Firebase Console.
In each game, we imported the google-services.json file. We use Firebase Analytics, Crashlytics, RemoteConfig, Database, and Storage services by Firebase.FirebaseApp.DefaultInstance (which is configured via the google-services.json file).
Everything related to these services mentioned above works as expected.

Regarding the authentication, we created a 6th Firebase application in Firebase Console that will be used by all 5 games. This is because we want the authentication to be cross-apps (users can log in to the same account in all the games).

To use this FirebaseApp in Unity, we create a FirebaseApp like this: Firebase.FirebaseApp.Create(AppOptions, "OurAuthApp").
This worked fine with the email verification. But there is a problem with the phone authentication.

Here is the code that causes the error:

` Firebase.Auth.PhoneAuthOptions phoneOptions = new Firebase.Auth.PhoneAuthOptions {
PhoneNumber = phoneNumber,
TimeoutInMilliseconds = 1000 * 60 * 3,
ForceResendingToken = null
};

PhoneAuth.VerifyPhoneNumber(phoneOptions,
    verificationCompleted: (credential) => {
        // Auto-sms-retrieval or instant validation has succeeded (Android only).
        // There is no need to input the verification code.
        // `credential` can be used instead of calling GetCredential().
    },

    verificationFailed: (error) => {
        Debug.Log("## Here is the error printed");
        Debug.Log(error);
        // The verification code was not sent.
        // `error` contains a human readable explanation of the problem.
    },

    codeSent: (id, token) => {
        // Verification code was successfully sent via SMS.
        // `id` contains the verification id that will need to passed in with
        // the code from the user when calling GetCredential().
        // `token` can be used if the user requests the code be sent again, to
        // tie the two requests together.
        // Firebase user has been created.
    },

    codeAutoRetrievalTimeOut: (id) => {
        // Called when the auto-sms-retrieval has timed out, based on the given
        // timeout parameter.
        // `id` contains the verification id of the request that timed out.
    }
);

`

This is the "human readable" error we get (it calls verificationFailed):

VerifyPhoneNumber: builder faild to create PhoneAuhtOptions <>c__DisplayClass37_0:<PhoneSignUp>b__1(String) Firebase.Auth.VerificationFailed:Invoke(String) Firebase.Auth.<>c__DisplayClass12_0:<VerificationFailedHandler>b__0() System.Action:Invoke() Firebase.ExceptionAggregator:Wrap(Action) Firebase.AppUtilPINVOKE:PollCallbacks() Firebase.AppUtil:PollCallbacks() Firebase.Platform.FirebaseHandler:Update()

By the way, on iOS everything works fine (including the phone authentication so the problem is only on Android).

How can I see more useful and detailed logs, the "human readable" error above isn't enough to understand what is missing.
Any ideas or potential solutions?

Thanks!

@paulinon paulinon removed the new New issue. label Jun 20, 2023
@paulinon
Copy link
Contributor

Thanks for bringing this to our attention, @Hasan-OG. I was also able to encounter this error message as well using our quickstart project. That said, I'll be relaying my observations to the team. For now, you may downgrade to an SDK version lower than 11.0.0 and utilize something like this:

protected void VerifyPhoneNumber() {
      var phoneAuthProvider = Firebase.Auth.PhoneAuthProvider.GetInstance(auth);
      phoneAuthProvider.VerifyPhoneNumber(phoneNumber, phoneAuthTimeoutMs, null,
        verificationCompleted: (cred) => {
          // Verification completed
        },
        verificationFailed: (error) => {
          Debug.Log("Phone Auth, verification failed: " + error);
        },
        codeSent: (id, token) => {
          phoneAuthVerificationId = id;
          Debug.Log("Phone Auth, code sent");
        },
        codeAutoRetrievalTimeOut: (id) => {
          Debug.Log("Phone Auth, auto-verification timed out");
        });
    }

@AlmostMatt
Copy link
Contributor

AlmostMatt commented Jun 24, 2023

I was able to reproduce this issue as well.
I have a potential fix in firebase/firebase-cpp-sdk#1360, which will hopefully resolve this issue in the Firebase Unity SDK 11.3.0 release in a few weeks.

In the meantime the best workaround is probably as paulinon suggests, which is to use version 10.7.0 or previous of the Unity SDK.

Edit: Closing the issue for now. The fix will be in the next release (11.3.0) when it goes out in a few weeks or so.

@AlmostMatt AlmostMatt self-assigned this Jun 26, 2023
@JankunChar
Copy link

@AlmostMatt I am also receiving same problem. I have created this forum.

#782 (comment)

As per your request. i have downgrade to 10.7.0. . I have received the following error.
Error1

Kindly quote which version i should work ( unity + firebase version )...

Did Firebase SMS is working or not?
My Build is in live. The Sms is not receiving. i am in deep trouble. Kindly do the needful.

@firebase firebase locked and limited conversation to collaborators Aug 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants