8

I am not able to settle this issue when implementing the new App Check feature from Firebase.

When uploading files to Firebase Storage it fails with an error

Caused by: java.io.IOException: { "error": { "code": 401, "message": "Firebase App Check token is invalid." }}

I already provided the debug secret just like what is in this documentation.

The debug apk was installed directly via USB debugging.

Note: I am using a physical device and enabled Enforce status on both Storage and Real-time database and it fails whenever I tried to do transaction like upload and the error above shows.

Bitwise DEVS
  • 2,858
  • 4
  • 24
  • 67
  • 2
    The documentation is incomplete ... I am stuck at same issue for almost 2 days and found no solution till now !!! – Ali Yar Khan Jun 19 '21 at 11:11
  • 1
    @AliYarKhan I just stop immediately when I cannot read any related article and documentation about it as it is very new product – Bitwise DEVS Jun 19 '21 at 18:11

3 Answers3

3

Run the App on Physical device. I was facing the same issue and but when i run the app on a physical device it is gone! Ensure you main run app funtion is like this

This is the code docs have mentioned:

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  await FirebaseAppCheck.instance.activate(webRecaptchaSiteKey: 'recaptcha-v3-site-key');
  runApp(MyApp());
}
iDecode
  • 22,623
  • 19
  • 99
  • 186
Ali Yar Khan
  • 1,231
  • 2
  • 11
  • 33
  • I am using physical device, have you enabled Enforce on Storage and Real-time database as well? You need to enable them to see if it really works completely – Bitwise DEVS Jun 19 '21 at 18:42
  • Let me know if you were able to make it work on Storage or Real-time database with `Enforce` status enabled. – Bitwise DEVS Jun 19 '21 at 18:59
  • yes ... it worked with enforce status .... please ensure you wrapped your run app function in these ```Future main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); await FirebaseAppCheck.instance.activate(webRecaptchaSiteKey: 'recaptcha-v3-site-key'); runApp(MyApp()); }``` – Ali Yar Khan Jun 20 '21 at 09:21
1

I have used a physical device, in my opinion, which is far better to use than an emulator. All you need is SHA 256 key and register your application in the safety net in project settings. To get SHA 256 key, just click on the Gradle tab in the leftmost corner in android studio. Click android folder within your application folder and run signiningReport. It will generate SHA 256 key in the terminal and copy it into the safety net. That's it.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Rashid Kamal
  • 131
  • 1
  • 3
  • That's all you need when appcheck is not buggy. I cannot debug today on iOS, getting "App not registered" false responses :( It happens sometimes, very annoying. – Vilmir Mar 30 '23 at 14:43
0

make sure to update all the Firebase related libraries first and try again. it shall work.

abhi
  • 961
  • 9
  • 13