firebase / FirebaseUI-Android

Optimized UI components for Firebase
https://firebaseopensource.com/projects/firebase/firebaseui-android/
Apache License 2.0
4.64k stars 1.83k forks source link

Phone Auth with Firebase App Check Debug Provider #2139

Open ArcherEmiya05 opened 1 year ago

ArcherEmiya05 commented 1 year ago

Welcome to FirebaseUI and thanks for submitting an issue!

Please take a look at open issues, as well as resolved issues, to see if your issue is either already being addressed, or has been solved by someone else.

If not, please feel free to fill in the following info so we can help faster!

Step 1: Are you in the right place?

Step 2: Describe your environment

Step 3: Describe the problem:

Steps to reproduce:

  1. Use Firebase Phone Auth
  2. Setup project with Firebase App Check
  3. Run the app in both emulator or physical device

Observed Results:

Failed to work with unknown error occurred message.

Expected Results:

How to work with Firebase App Check Play Integrity Debug Provider since Firebase Phone Auth now is no longer working with deprecated SafetyNet?

Relevant Code:

Error logs:

Error getting App Check token; using placeholder token instead. Error: com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed.
Error getting App Check token; using placeholder token instead. Error: com.google.firebase.FirebaseException: Too many attempts.

[SmsRetrieverHelper] SMS verification code request failed: unknown status code: 18002 Invalid PlayIntegrity token; app not Recognized by Play Store.

SMS verification code request failed: unknown status code: 17093 null

com.google.firebase.auth.FirebaseAuthException: This request is missing a valid app identifier, meaning that Play Integrity checks, and reCAPTCHA checks were unsuccessful. Please try again, or check the logcat for more details.

We already generated a debug token App Check in console, already added both debug and release SHA 256 under Play Integrity. Then we add this codes:

build.gradle

   defaultConfig {
      testInstrumentationRunnerArguments["firebaseAppCheckDebugSecret"] = "DEBUG_TOKEN"
   }

    api 'com.google.firebase:firebase-appcheck-playintegrity:17.0.1'
    api 'com.google.firebase:firebase-appcheck-debug:17.0.1'
    api 'com.google.firebase:firebase-appcheck-ktx:17.0.1'
    api 'com.google.android.play:integrity:1.2.0'

    api 'com.google.firebase:firebase-appcheck-debug-testing:17.0.1'

Application.kt

       FirebaseApp.initializeApp(this)

        debugAppCheckTestHelper.withDebugProvider {
            // Test code that requires a debug AppCheckToken.
        }

        Firebase.analytics.setAnalyticsCollectionEnabled(BuildConfig.DEBUG.not())
        Firebase.crashlytics.setCrashlyticsCollectionEnabled(BuildConfig.DEBUG.not())
        Firebase.messaging.subscribeToTopic(AppConfig.FCM_TOPIC_ANNOUNCEMENT)

        Firebase.appCheck.installAppCheckProviderFactory(
            if (BuildConfig.DEBUG)
                DebugAppCheckProviderFactory.getInstance()
            else
                PlayIntegrityAppCheckProviderFactory.getInstance()
        )

Currently we are stuck since we do not know how to let Firebase UI's Firebase Auth know that we are using Debug Token

arjun42squar commented 1 year ago

I also faced this issue. This error log denotes that reCAPTCHA failed in the process, This can be solved by changing your default browser to another option or clearing the data of your available browser, My issue was solved when changed to Chrome. Still, this is not a best practice. Play Integrity only works if we download the app from the Play Store so I'm waiting to do it when the app is published in Play Store