Encountering an issue while attempting to call a callable function from Flutter:
W/FirebaseContextProvider( 3655): Error retrieving App Check token. Issue: com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed.
D/TrafficStats( 3655): tagSocket(294) with statsTag=0xffffffff, statsUid=-1
E/flutter ( 3655): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_functions/permission-denied] PERMISSION_DENIED
E/flutter ( 3655):
E/flutter ( 3655): #0 StandardMethodCodec.decodeEnvelope
message_codecs.dart:653
E/flutter ( 3655): #1 MethodChannel._invokeMethod
platform_channel.dart:315
E/flutter ( 3655): <asynchronous suspension>
E/flutter ( 3655): #2 MethodChannelHttpsCallable.call
method_channel_https_callable.dart:22
E/flutter ( 3655): <asynchronous suspension>
E/flutter ( 3655): #3 HttpsCallable.call
https_callable.dart:49
E/flutter ( 3655): <asynchronous suspension>
E/flutter ( 3655): #4 _SendFeedbackModalBottomSheetState.build.<anonymous closure>
send_feedback.dart:90
E/flutter ( 3655): <asynchronous suspension>
E/flutter ( 3655):
E/flutter ( 3655): #0 StandardMethodCodec.decodeEnvelope
message_codecs.dart:653
E/flutter ( 3655): #1 MethodChannel._invokeMethod
platform_channel.dart:315
E/flutter ( 3655): <asynchronous suspension>
E/flutter ( 3655): #2 MethodChannelHttpsCallable.call
method_channel_https_callable.dart:22
E/flutter ( 3655): <asynchronous suspension>
E/flutter ( 3655): #3 HttpsCallable.call
https_callable.dart:49
E/flutter ( 3655): <asynchronous suspension>
E/flutter ( 3655): #4 _SendFeedbackModalBottomSheetState.build.<anonymous closure>
send_feedback.dart:90
E/flutter ( 3655): <asynchronous suspension>
E/flutter ( 3655):
Below is the invocation of the callable function:
final HttpsCallable callable = FirebaseFunctions.instance.httpsCallable('sendFeedback');
final resp = await callable.call(<String, dynamic>{
'email': '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7c1f090f081311190e3c19041d110c1019521f1311">[email protected]</a>',
'message': message,
});
Shown here is the structure of the cloud function:
const sendgridApiKey = functions.config().sendgrid.key;
sgMail.setApiKey(sendgridApiKey);
export const sendFeedback = functions.https.onCall(async (data, context) => {
// Verify user authentication
if (!context.auth) {
throw new functions.https.HttpsError("unauthenticated", "User is not authenticated");
}
const message = data.message;
try {
// Create email message
const emailMessage = {
to: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="cba3aea7a7a48baeb3aaa6bba7aee5a8a4a6">[email protected]</a>",
from: "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="056b6a28776075697c45607d64687569602b666a68">[email protected]</a>",
subject: "Feedback from user",
text: message,
};
// Utilize SendGrid to send email
await sgMail.send(emailMessage);
return {
success: true, message: "Email sent successfully",
};
} catch (error) {
console.error("Error sending email:", error);
throw new functions.https.HttpsError("internal", "An error occurred while sending the email");
}
});
This problem occurs on both the emulator and physical device. Ensured that the service account "App Engine default service account" has been assigned the role of "Editor". Is there something I am overlooking to resolve this permission issue?
Update: Attempted to employ the App Check debug token as suggested at https://firebase.google.com/docs/app-check/flutter/debug-provider#android and no longer facing the error "Error getting App Check token. Error: com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed". However, the permission denied error persists.