'Implement Firebase App Check for Flutter app
I want to add Firebase App Check service to my Flutter app. I found this tutorial: https://firebase.flutter.dev/docs/app-check/usage, I have been able to complete these steps, however I do not get how should I add X-Firebase-AppCheck
header inside every request and where should I get it from. I want to protect my custom backend in Node.js from requests outside my Flutter app. I found this tutorial https://firebase.googleblog.com/2021/10/protecting-backends-with-app-check.html that explains how to add a simple middleware that validates X-Firebase-AppCheck
header and I get this. But regarding the client, how do I get the SafetyNet
or App Attest
tokens that I can send to api? Is it provided by package:firebase_app_check/firebase_app_check.dart
or some native implementations on both Android and iOS are required in order to get it?
I hope someone could help me understand how this flow works so that I will be able to make this work.
Solution 1:[1]
You can use something like this:
Future<Map<String, String>> getAppCheckHeader() async {
String? appCheckToken = await FirebaseAppCheck.instance.getToken();
if (appCheckToken == null) throw 'noAppCheckToken found';
return {
'X-Firebase-AppCheck': appCheckToken,
};
}
This will retrieve the current App Check token using the Flutterfire package.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |