skip to Main Content

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.

2

Answers


  1. Edit Answer

    For CI/CD Pipeline

    When you want to test using an Android virtual device -or- when you prefer to (re)use a token of your choice — e.g. when configuring a CI/CD pipeline — use the following steps:

    • In the Project Settings > App Check section of the Firebase console, choose Manage debug tokens from your app’s overflow menu. Then, register a new debug token by clicking the Add debug token button, then Generate token.

    • Pass the token you created in the previous step by supplying a FIREBASE_APP_CHECK_DEBUG_TOKEN environment variable to the process that build your android app. e.g.:

      FIREBASE_APP_CHECK_DEBUG_TOKEN="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" run-android

    Please note that once the android app has successfully passed the
    app-checks controls on the device, it will keep passing them, whether
    you rebuild without the secret token or not. To completely reset
    app-check, you must first uninstall, and then re-build / install.

    For Emulator

    There are a variety of other ways to obtain and configure debug tokens for AppCheck testing, a few of which follow:

    Start your application on the android device.

    Use $adb logcat | grep DebugAppCheckProvider to grab your temporary secret from the android logs. The output should look lit this:

    D DebugAppCheckProvider: Enter this debug secret into the allow list in
    the Firebase Console for your project: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
    

    In the Project Settings > App Check section of the Firebase console, choose Manage debug tokens from your app’s overflow menu. Then, register the debug token you logged in the previous step.

    Success Sample Result;

    App Check Result for debug token

    Help Source : https://rnfirebase.io/app-check/usage

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search