Google play integrity API - Invalid app check token error after adding app to Firebase project

3.3k views Asked by At

I am trying to implement firebase app check in my android app using Play-Integrity API. I have added both my SHA-1 & SHA-256 fingerprints in my firebase app (acquired from Google play console and Android studio gradle signing report both) into my firebase app.

I have added this code inside all my activities in my app, before using any other Firebase SDKs:

@Override
protected void onCreate(Bundle savedInstanceState) {
    FirebaseApp.initializeApp(this);
    FirebaseAppCheck firebaseAppCheck = FirebaseAppCheck.getInstance();
    firebaseAppCheck.installAppCheckProviderFactory(PlayIntegrityAppCheckProviderFactory.getInstance());
}

Now no matter how many times I run my app, I keep getting the error in my console:

pc_0 - Detected invalid AppCheck token. Reconnecting (2 attempts remaining)
pc_0 - Detected invalid AppCheck token. Reconnecting (1 attempts remaining)
pc_0 - Detected invalid AppCheck token. Reconnecting (0 attempts remaining)

pc_0 - Firebase Database connection was forcefully killed by the server. Will not attempt reconnect. Reason: Invalid appcheck token

I have followed all the steps exactly as mentioned in this page. My app is already uploaded in Google play store, and Google Play Integrity API is already enabled in Google cloud console. What more do I need to do? Please help me.

1

There are 1 answers

0
ismail alaoui On

if you are under debug mode you should add debug token to your appcheck :

Appcheck -- > Application -- > Manage debug token

add this line to your gradle :

    implementation 'com.google.firebase:firebase-appcheck-debug:16.1.2'

And then instantiate your appcheck this way :

   FirebaseApp.initializeApp(getApplicationContext());
   FirebaseAppCheck firebaseAppCheck = FirebaseAppCheck.getInstance();
   firebaseAppCheck.installAppCheckProviderFactory(
            DebugAppCheckProviderFactory.getInstance());

After that , lunch your application , in your logcat , look for this :

D DebugAppCheckProvider: Enter this debug secret into the allow list in
the Firebase Console for your project: 123a4567-b89c-12d3-e456-789012345678

So you need to add this token 123a4567-b89c-12d3-e456-789012345678 in your Appcheck debug token .

this should work for you !