My requirement is to use one Android app to access two Firebase projects. I am using Authentication, Cloud Firestore, Realtime Database, Cloud Storage and Cloud Functions in my Android project. I need to have the same app with a configurable Firebase backend so that it can be configured to access the respective I am trying to access two Firebase projects from an Android app, by configuring the FirebaseOptions as given below,
val builder = FirebaseOptions.Builder()
.setApplicationId("<my_app_id>")
.setApiKey("<api_key>")
.setDatabaseUrl("<url>")
.setStorageBucket("<storage_bucket>")
.setProjectId("<project_id>")
val firebaseApp = FirebaseApp.initializeApp(context, builder.build())
firebaseAuth = Firebase.auth(firebaseApp)
I am trying email authentication and phone authentication. Both are successful in the original Firebase project, but while trying with second Firebase project, email authentication is successful but phone authentication fails.
The following is the error message when I try Phone Authentication,
This app is not authorized to use Firebase Authentication. Please verify that the correct package name and SHA-1 are configured in the Firebase Console. [ A safety_net_token was passed, but no matching SHA-256 was registered in the Firebase console. Please make sure that this application’s packageName/SHA256 pair is registered in the Firebase Console. ]
I have also tried enabling Android device Verification in the GCP console.
Also tried the following,
val firebaseApp = FirebaseApp.initializeApp(context, builder.build(), "secondary")
firebaseAuth = Firebase.auth(FirebaseApp.getInstance("secondary"))
For initiating the phone number verification process, I use the following code,
val options = PhoneAuthOptions.newBuilder(RemoFirebase.getInstance().firebaseAuth)
.setPhoneNumber(phoneNumber) // Phone number to verify
.setTimeout(60L, TimeUnit.SECONDS) // Timeout and unit
.setActivity(this) // Activity (for callback binding)
.setCallbacks(mCallbacks) // OnVerificationStateChangedCallbacks
.build()
PhoneAuthProvider.verifyPhoneNumber(options)
When trying with the default project settings, that is by using the configurations for the original project, I have no problem what so ever.
Is there any other way to achieve my requirement ?