Can not generate a debug token for Firebase Storage with App Check

1,958

Try to download your google-services.json again.

If this does not help, might need to add/re-add your debug key's SHA-1 certificate after doing so, get new google-services.json

Apparently being blocked by firebase means your API key is configured improperly.

If you are getting this error:

 Error: com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed. 

Check your SafetyNet provider in the Project Settings > App Check. You will need to provide SHA-256 fingerprint of your app's signing certificate. (would also suggest increasing token live time)

Share:
1,958
Florian
Author by

Florian

Flutter 💻

Updated on December 02, 2022

Comments

  • Florian
    Florian over 1 year

    I want to include Firebase App Check for Firebase Storage in my Android Flutter App. Therefore I was following the official documentation: 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:

    Error getting App Check token; using placeholder token instead. Error: com.google.firebase.FirebaseException: Error returned from API. code: 403 body: Requests from this Android client application are blocked.

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

    • Maciej Caputa
      Maciej Caputa over 2 years
      I have the same issue, were you able to resolve it?
    • I AM
      I AM over 2 years
      How did you solve this ?
    • Florian
      Florian over 2 years
      I did nor solve this issue
    • Marcello Câmara
      Marcello Câmara over 2 years
      I don't even receive the printed log information... The doc is very poor
  • Maciej Caputa
    Maciej Caputa over 2 years
    Thank you for your suggestion. I've just removed and added my debug and release SHA-1 keys to firebase and downloaded google-services.json again, but the same issue is printed when I want to call an https function: Error getting App Check token; using placeholder token instead. Error: com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed.
  • Maciej Caputa
    Maciej Caputa over 2 years
    thank you for the update 1. I've removed all SHA-1 keys and added both my release and debug keys to firebase project. 2. Dowloaded google-service.json again and added it to my project. 3. I've added both SHA-256 keys (release and debug) to SafetyNet. 4. Why do you suggest to increase token live time? And to what do you suggest to increase it to? 5. I added a call to firebae callable function of app start and it works in debug mode on my real device. I will now deploy to production and see if it works. :)
  • Maciej Caputa
    Maciej Caputa over 2 years
    Update: Good thing is that I've managed to get this working on iOS but the problem still remains on Android. Interestingly, when I have a real device connected it works even without registering debug token. Do you have an idea what can I try?
  • Florian
    Florian over 2 years
    Thank you, but this does not work for me either. But I have a feeling that it has something to do with my MainActivity.kt file. When I make a request to Firebase Storage, no AppCheckToken gets printed to my console. So I think this line firebaseAppCheck.installAppCheckProviderFactory(DebugAppChec‌​kProviderFactory.get‌​Instance()) gets never executed to generate a new Debug-Token for me.
  • Anh Tran
    Anh Tran over 2 years
    Please make sure that .MainActivity is declared as your main activity name at AndroidManifest.xml: ` ... <activity android:name=".MainActivity" android:launchMode="singleTop" android:theme="@style/LaunchTheme" `
  • ABDERRAHMANE OUALI
    ABDERRAHMANE OUALI over 2 years
    [SOLVED] I did generate SHA-256 key from the following comand cd android && ./gradlew signingReport then look for the appsigning with variant Debug and copied SHA-256 string into the firebase console Project setting > app check and clicked safety net and pasted the string into it