[Fixed] Firebase app check with Play integrity not returning token giving 403 error GeneratePlayIntegrityChallenge are blocked – Firebase

by
Ali Hasan
android firebase firebase-app-check google-play-integrity-api

Quick Fix: Check the Android key used by App Check in your Google Cloud console. Ensure it’s not restricted and that the Firebase App Check API is allowed for that key. Without this permission, you’ll encounter the ‘google.firebase.appcheck.v1.TokenExchangeService.ExchangeDebugToken are blocked’ error.

The Problem:

Firebase App Check integration with Play Integrity is failing with a 403 error. The getAppCheckToken method is not returning a token and instead throws an exception indicating that requests to the ExchangeDebugToken API are blocked.

The Solutions:

Solution: Keys and API Access

Firebase App Check uses an Android key for token generation. Ensure that this key, found in the Google Cloud Console, is not restricted. Additionally, grant access to Firebase App Check API for the key. Failure to do so will result in the error: "Requests to this API firebaseappcheck.googleapis.com method google.firebase.appcheck.v1.TokenExchangeService.ExchangeDebugToken are blocked."

  • Navigate to the Google Cloud Console and locate the Android key.
  • Check that the key is not restricted.
  • Grant access to Firebase App Check API for the key.

Solution

Follow these steps:

  1. Set up "App Check" in Firebase console for Auth, Firestore, Storage, etc.
  2. Add "firebase app check" package in your Flutter project.
  3. Add the following code in "main.dart" in the main method:
void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);

  FirebaseAppCheck firebaseAppCheck = FirebaseAppCheck.instance;
  firebaseAppCheck.activate(androidProvider: AndroidProvider.debug);
  firebaseAppCheck.getToken();
}
  1. Restart your project.

You will see the following token on the console:

Enter this debug secret into the allowlist in the Firebase Console for your project:
-*************

  1. Copy this token and add it in Firebase console > Appcheck > Apps > Three dots > Add debug token.

Q&A

Play Integrity check with App Check is not giving token giving 403 error

Turns out that App Check uses an android key for token generation. Make sure that this key is not disabled and that you have allowed App Check API for that key.

Follow these steps to fix the 403 error

Setup App Check in console, add app_check package in flutter project, add code in main.dart in main method, get token, and add it in console.