1

I have enabled AppCheck and PlayIntegrity in Firebase. However when I trigger a callable function, 2 things happens here:

  1. App Verification is not happening (See the Firebase function log below).
  2. The Push notification that I suppose to receive in the onCall function does not trigger.

This is the error I receive:

W/FirebaseContextProvider(25810): Error getting App Check token. Error: com.google.firebase.FirebaseException: Too many attempts.

NOTE: If I remove the

.runWith({
        enforceAppCheck: true
    })

and,

 if (context.app == undefined) {
     throw new functions.https.HttpsError(
        'failed-precondition',
        'The function must be called from an App Check verified app.')
 }

The push notification is received successfully.

Firebase Function Log in Google Cloud

Summary of the log => functionName158nxe4tcyx4 Callable request verification passed

jsonPayload: {
    message: "Callable request verification passed"
    verifications: {
    auth: "VALID"
    app: "MISSING" // THIS IS THE PROBLEM NO.1
    }
}

My Flutter code is as follows:

Firebase Initialisation

import 'package:firebase_app_check/firebase_app_check.dart';

 Future<void> initFirebase() async {
    WidgetsFlutterBinding.ensureInitialized();
    await Firebase.initializeApp();
    await FirebaseAppCheck.instance.activate(
      webRecaptchaSiteKey: 'recaptcha-v3-site-key',
      androidProvider: AndroidProvider.playIntegrity, //Tried with enum 'debug' in emulator and 'playIntegrity' in real device
);

Firebase Callable from Flutter

 HttpsCallable callable =
          FirebaseFunctions.instanceFor(region: 'my-area')
              .httpsCallable('functionName');
      await callable.call(<String, dynamic>{
        'token': pushToken,
        'username': '$userName',
  });

Firebase Function

exports.functionName = functions
    .region('my-area')
    .runWith({
        enforceAppCheck: true
    })
    .https.onCall(async (data, context) => {
        
        if (context.app == undefined) {
            throw new functions.https.HttpsError(
                'failed-precondition',
                'The function must be called from an App Check verified app.')
        }
        //My task of sending push notification starts from here. 
        //THIS IS PROBLEM NO.2, NOT EXECUTING
        const token = data.token;
        const isApproved = data.isApproved;
        const payLoad = {
            data: { 'type': 'approvalStatus' },
            notification: {
                title: `Approval Status Update`,
                body: isApproved ? `Some description Text here`,
                clickAction: 'FLUTTER_NOTIFICATION_CLICK'
            }
        };
        return fcm.sendToDevice(token, payLoad);
    });

0 Answers0