Search code examples
androidfirebasefirebase-app-check

How to setup firebase app check debug tokens for real device while testing across multiple install/uninstall?


We are able to test firebase app check using debug provider on a real device by

  • launching the app on the real device and copy the token from logs
  • then we configure this copied token in firebase console as per the documentation.

It has a couple of problems

  1. Needs manual configuration each time token changes due to re-installation of the on the same or new device
  2. It will not be very convenient when we will give app to more internal testers. Its impractical in that case to manually configure the tokens

Am I missing something from documentation? I am sure many other might have faced this issue.

need some help here.

Thanks.


Solution

  • I also faced such a problem. I looked at the Firebase App Check code and this is what I got:

    val persistenceKey = FirebaseApp.getPersistenceKey(
        FirebaseApp.DEFAULT_APP_NAME,
        FirebaseOptions.fromResource(context)
    )
    val prefsName = String.format("com.google.firebase.appcheck.debug.store.%s", persistenceKey)
    val sharedPreferences = context.getSharedPreferences(prefsName, Context.MODE_PRIVATE)
    val secretKey = "com.google.firebase.appcheck.debug.DEBUG_SECRET"
    sharedPreferences.edit().putString(secretKey, "YOUR TOKEN").apply()
    FirebaseApp.initializeApp(context)