I built an app that uses flutter
, Firebase Firestore
and Firebase Authentication
.
I published my app in both Android Play store
(internal tests) and Apple App Store
(Testflight
) using the exact same flutter
base code.
The Problem:
Why does App check not recognize some Android requests (Unverified: invalid requests) every few hours while it recognizes all the rest as verified... meanwhile App Check recognizes (verified requests) 100% of the iPhone requests? and it even recognizes the same android ones when I just restart the app from the device
Explanation:
- Here is a Snapshot showing only the Android app requests (from 1 device): You can see the "unverified" at the beginning (see red arrow in graph), then it becomes all "verified" for a few hours, then again 1 "unverified" (not shown here) and so on.
2 - And here is a Snapshot showing only the iPhone app requests (from 1 device): You can see that everything is "verified" as expected, even after several hours or days.
The Code:
Future <void> main() async{
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform,);
await FirebaseAppCheck.instance.activate(
androidProvider: AndroidProvider.playIntegrity, appleProvider: AppleProvider.appAttestWithDeviceCheckFallback);
runApp(AuthUserProviderWidget());
}
For the signing key, I use the one from Google Play Console > Release > Setup > App Signing > App signing key certificate > SHA-256
and I copy that SHA-256 to Firebase > App Check > Apps > Android > Play Integrity >SHA-256 certificate fingerprint
Update 1:
I have tried "enforcing" appcheck: same outcome... I have tried a different Android phone device: same thing (mostly "verified" until after a few hours I get the "unverified" one)... I have tried using the SHA256 of the "Upload key": this one does not work at all with appcheck... I am lost, any ideas anyone???
Update 2:
I used kReleaseMode
to confirm it is release mode... but still same issue with Android:All requests are verified, then randomly one request is unverified and blocked... then again, subsequent calls are verified again... I also updated to last versions of flutter (3.13.4) and Appcheck 0.2.0 and all Firebase... Still same...
Because the fact that rerunning the app after the error always runs smoothly, I also tried to add artificial delays after initializing Firebase and after activating AppCheck... I also tried to activate multiple times... I tried await FirebaseAppCheck.instance.setTokenAutoRefreshEnabled(true);
... Still the same random error, once every few hours
Update 3:
See "Partial Solution" described below... Basically, I was able to reduce the frequency of this error by forcing a getToken(true)
and setTokenAutoRefreshEnabled(true)
... But error still happens every few hours... It seems to happen when the app comes back to foreground from a long time in the background
Update 4: 2 months after this question, I am still actively looking for a solution... Also looking if anyone else is experiencing this same error or is it just me?