androidfirebasefirebaseuifirebase-app-checkgoogle-play-integrity-api

How to use Firebase App Check Play Integrity Debug Token?


Following the documentation, we are struggling to make it work with Firebase App Check using a Debug Token for App Check. Currently this is what we ended up upon following the docs.

build.gradle (submodule)

 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 class

   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.appCheck.installAppCheckProviderFactory(
        if (BuildConfig.DEBUG)
            DebugAppCheckProviderFactory.getInstance()
        else
            PlayIntegrityAppCheckProviderFactory.getInstance()
    )

We are stuck and do not know how to utilize the debug testing, what we understand is we can provide a Debug Provider Factory using the generated debug token in Firebase Console App Check but it seems that is not how it works.

What we wanted to do is run the app on emulator or physical device manually then later via CI CD with Firebase Test Lab before hitting the production stage and publish it in Play Store. We are also using Firebase Auth UI (Phone) and it is no longer working when running on a debug build.

P.S. This is probably the most dire feature ever introduced as there seems to be not many topics about this and proper working sample that covers all possible use cases.


Solution

  • Currently there is no clear way to use it, the one from the docs seems to work only for unit testing not instrumental. There is already a reported issue as well in Firebase UI for Android repo where Phone Auth is not working due to App Check Play Integrity dependency failing on both physical and virtual and no one has definitive answer yet. I suggest that for the mean time create a test account in Firebase Console authentication section. Using test accounts will skip the integrity check thus allowing you to run the app in any devices including virtual.