firebase / firebase-unity-sdk

The Firebase SDK for Unity
http://firebase.google.com
Apache License 2.0
215 stars 35 forks source link

Allow to provide the ClientId to Firebase.AppOptions #380

Open gindemit opened 3 years ago

gindemit commented 3 years ago

[REQUIRED] Please fill in the following fields:

[REQUIRED] Please describe the issue here:

Hey Firebase team! The problem: If the user tries to register or login using his phone number the app crashes on iOS. Our use case: Currently we use custom Firebase apps. The app is configured from the code like this:

internal static Firebase.FirebaseApp CreateFirebaseAppBaseOnConfiguration()
{
    Firebase.AppOptions appOptions = new Firebase.AppOptions() {
        AppId = APP_ID,
        ApiKey = API_KEY,
        StorageBucket = STORAGE_BUCKET,
        ProjectId = PROJECT_ID
    };
    Firebase.FirebaseApp app = Firebase.FirebaseApp.Create(appOptions, "SoulsideFirebaseApp");
    return app;
}

The created Firebase app reference is provided to the Firebase services like this: _auth = Firebase.Auth.FirebaseAuth.GetAuth(app); When the VerifyPhoneNumber method is called we get an crash:

PhoneAuthProvider provider = PhoneAuthProvider.GetInstance(_auth);
provider.VerifyPhoneNumber(...); // <--- The crash happens here!

The crash is unhandled exception that is thrown in Pods/FirebaseAuth/FIRPhoneAuthProvider.m ObjectiveC class on line 125:

- (void)verifyPhoneNumber:(NSString *)phoneNumber
        UIDelegate:(nullable id<FIRAuthUIDelegate>)UIDelegate
        completion:(nullable FIRVerificationResultCallback)completion {
 if (![FIRAuthWebUtils isCallbackSchemeRegisteredForCustomURLScheme:_callbackScheme]) {
  [NSException raise:NSInternalInconsistencyException
        format:@"Please register custom URL scheme '%@' in the app's Info.plist file.",
            _callbackScheme];
 }

The _callbackScheme is nil. It is initialized from _auth.app.options.clientID in the same file:

- (nullable instancetype)initWithAuth:(FIRAuth *)auth {
 self = [super init];
 if (self) {
  _auth = auth;
  _callbackScheme = [[[_auth.app.options.clientID componentsSeparatedByString:@"."]
              reverseObjectEnumerator].allObjects componentsJoinedByString:@"."];
 }
 return self;
}

When a custom Firebase app (configured from C# code, see above) is used the _auth.app.options dictionary contains 6 key/values. If we use the Firebase.FirebaseApp.DefaultInstance for the Auth the _auth.app.options dictionary contains 8 key/values. The two additional key/values are: CLIENT_ID and DATABASE_URL.

If we go to the C# Firebase.AppOptions class we will see that we can not provide the ClientId. But it is required in iOS verifyPhoneNumber method.

Steps to reproduce:

Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)? No What's the issue repro rate? (eg 100%, 1/5 etc)

What happened? How can we make the problem occur? Try the provide custom ClientId to the Firebase.AppOptions. This could be a description, log/console output, etc.

If you have a downloadable sample project that reproduces the bug you're reporting, you will likely receive a faster response on your issue.

Relevant Code:

Firebase.AppOptions appOptions = new Firebase.AppOptions() {
    AppId = APP_ID,
    ApiKey = API_KEY,
    StorageBucket = STORAGE_BUCKET,
    ProjectId = PROJECT_ID
    // Can not provide ClientId here
};
Firebase.FirebaseApp app = Firebase.FirebaseApp.Create(appOptions, "SoulsideFirebaseApp");
return app;
DellaBitta commented 3 years ago

Thanks for this ticket and I'm sorry for the inconvenience. We'll work to add a feature that includes an API surface for client ids in the Firebase Option configuration flow.