我在 Flutter 中检查 Firebase 应用程序时出现错误

问题描述 投票:0回答:1

我想在 Flutter 中使用 Play Integrity,因此我使用 Firebase App Check。但它发生了错误。我运行它来获取调试令牌以在 Firebase 中使用。删除 getToken() 时没有错误。我删除了这是我的错误。

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>

这是我的代码。

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(),
    );
  }
}

如何修复此错误?

flutter firebase firebase-app-check
1个回答
0
投票

拨打

getToken()
后无需再拨打
activate()
。请参阅 https://firebase.google.com/docs/app-check/flutter/debug-provider#android 中的示例。对
activate()
的调用应产生类似于打印调试令牌的示例中所示的控制台输出。 Firebase 客户端库会在对相应服务的请求中自动包含该令牌,因此通常不需要直接访问该令牌。

© www.soinside.com 2019 - 2024. All rights reserved.