I want to use Play Integrity in Flutter, so I use Firebase App Check. But it occured errors. I ran it to get debug token to use in Firebase. There is no error when delete getToken().I delete Here is my error.
E/flutter (15118): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: [firebase_app_check/unknown] com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed.
E/flutter (15118): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652:7)
E/flutter (15118): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18)
E/flutter (15118): <asynchronous suspension>
E/flutter (15118): #2 MethodChannelFirebaseAppCheck.getToken (package:firebase_app_check_platform_interface/src/method_channel/method_channel_firebase_app_check.dart:100:22)
E/flutter (15118): <asynchronous suspension>
E/flutter (15118): #3 main (package:app/main.dart:18:9)
E/flutter (15118): <asynchronous suspension>
And this is my code.
import 'package:firebase_app_check/firebase_app_check.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:app/screens/splash_screen.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase/firebase_options.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
await FirebaseAppCheck.instance.activate(
androidProvider: AndroidProvider.debug,
);
print(await FirebaseAppCheck.instance.getToken());
runApp(
const App(),
);
}
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false,
title: "App",
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
home: SplashScreen(),
);
}
}
How can I fix this error?
It isn't necessary to call getToken()
after calling activate()
. See the example at https://firebase.google.com/docs/app-check/flutter/debug-provider#android. The call to activate()
should produce console output similar to what's shown in the example printing out the debug token. The Firebase client libraries include that token automatically in requests to the respective services, so it's generally not necessary to access the token directly.