Error getting App Check token; using placeholder token instead
Asked Answered
V

2

18

My app was working normally since today.I already included Firebase Storage in my Android Flutter App and it works after that today I get AppCheck Errors suddenly. I was not include App Check for our project or not enforced in settings. After that I was following the official documentation for initialization appcheck : https://firebase.flutter.dev/docs/app-check/usage.

This is my Kotlin MainActivity:

import android.os.Bundle
import com.google.firebase.FirebaseApp
import com.google.firebase.appcheck.FirebaseAppCheck
import com.google.firebase.appcheck.debug.DebugAppCheckProviderFactory
import io.flutter.embedding.android.FlutterActivity


class MainActivity : FlutterActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        FirebaseApp.initializeApp(/*context=*/ this);
        val firebaseAppCheck = FirebaseAppCheck.getInstance()
        firebaseAppCheck.installAppCheckProviderFactory(
                DebugAppCheckProviderFactory.getInstance())
        super.onCreate(savedInstanceState)
    }
}

and this is my main():

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  await FirebaseAppCheck.instance.activate();
  runApp(MyApp());
}

I also added this to my app/build.gradle

dependencies {
  implementation 'com.google.firebase:firebase-appcheck-debug:16.0.0-beta01'
}

When I make a request to firebase storage, I would expect something like this in my console:

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

Instead, I'm getting an error:

2021-11-21 18:11:51.442 2091-3452/com.sekspir.grind4gain W/ExponenentialBackoff: network unavailable, sleeping.
2021-11-21 18:11:53.500 2091-3452/com.sekspir.grind4gain W/StorageUtil: Error getting App Check token; using placeholder token instead. Error: com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed.
2021-11-21 18:12:11.136 2091-3633/com.sekspir.grind4gain V/NativeCrypto: SSL handshake aborted: ssl=0xdaa42da8: I/O error during system call, Connection reset by peer

Did I miss something here? I am using a real Android device with flutter debug build.

This is Firestore AppCheck Stats looks both of request income Firestore AppCheck Stats

But in Storage session there are not any request fail or success. App Check Storage Stat

Valdes answered 21/11, 2021 at 20:20 Comment(1)
Could you please confirm that your Android log level is set to DEBUG level and above? This is to make sure the DebugAppCheckProvider: Enter this debug secret into the allow list in the Firebase Console for your project: 123a4567-b89c-12d3-e456-789012345678 logcat entry isn't being filtered out.Assizes
B
3

I get it what your issue might be. I was facing the same problem but in my case the issue was that I changed the application name and application id (com.example.appname) for releasing. But this application id was not updated in Firebase console. So you basically need to update the google-services.json file in your app with the updated application Id. And for that follow the below steps

  1. Create a new app with the updated package name (put your new application id there) in the firebase console.
  2. Download the new google-services file(this is the main step) and now copy the content of this new google-services file. Now go back to your android/flutter app and replace the content of old google-services.json file with the content of new google-services.json(that you copied).
  3. Now add the SHA keys to your new app in the firebase console.
  4. Now rebuild your flutter/android app and it should work.
Bisector answered 19/9, 2023 at 8:37 Comment(0)
A
2

Can you double check that you correctly enabled the enforcement ?
It is required to work with Firebase Storage solutions.

Are you using your app in "PWA" mode or in "Native" mode ?
The Recaptcha may be mandatory depending on how your app is distributed.

  await FirebaseAppCheck.instance.activate(
    webRecaptchaSiteKey: 'recaptcha-v3-site-key',
  );

I'm not sure about your implementation of the appcheck-debug dependency on the Android Native side.
Since it's already implemented by the Flutter library itself, you should remove it.

Personal note : I had troubles with FirebaseAppCheck on some devices, while it was working perfectly on other devices.
This library is still in beta and I would recommend to wait before using it in production.

Asclepius answered 27/7, 2022 at 7:2 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.