【问题标题】:Error getting App Check token; using placeholder token instead获取 App Check 令牌时出错;改用占位符令牌
【发布时间】:2022-07-27 15:02:57
【问题描述】:

我的应用程序从今天开始运行正常。我已经在我的 Android Flutter 应用程序中包含了 Firebase 存储,之后它就可以运行了,今天我突然收到 AppCheck 错误。我没有为我们的项目包含 App Check,也没有在设置中强制执行。之后,我关注了初始化 appcheck 的官方文档:https://firebase.flutter.dev/docs/app-check/usage.

这是我的 Kotlin MainActivity:

import android.os.Bundle
import com.google.firebase.FirebaseApp
import com.google.firebase.appcheck.FirebaseAppCheck
import com.google.firebase.appcheck.debug.DebugAppCheckProviderFactory
import io.flutter.embedding.android.FlutterActivity


class MainActivity : FlutterActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        FirebaseApp.initializeApp(/*context=*/ this);
        val firebaseAppCheck = FirebaseAppCheck.getInstance()
        firebaseAppCheck.installAppCheckProviderFactory(
                DebugAppCheckProviderFactory.getInstance())
        super.onCreate(savedInstanceState)
    }
}

这是我的 main():

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  await FirebaseAppCheck.instance.activate();
  runApp(MyApp());
}

我也将此添加到我的 app/build.gradle

dependencies {
  implementation 'com.google.firebase:firebase-appcheck-debug:16.0.0-beta01'
}

当我向 firebase 存储发出请求时,我希望控制台中出现类似的内容:

D DebugAppCheckProvider:将此调试密码输入到您项目的 Firebase 控制台的允许列表中:123a4567-b89c-12d3-e456-789012345678

相反,我收到了一个错误:

2021-11-21 18:11:51.442 2091-3452/com.sekspir.grind4gain W/ExponenentialBackoff: network unavailable, sleeping.
2021-11-21 18:11:53.500 2091-3452/com.sekspir.grind4gain W/StorageUtil: Error getting App Check token; using placeholder token instead. Error: com.google.firebase.FirebaseException: Error returned from API. code: 403 body: App attestation failed.
2021-11-21 18:12:11.136 2091-3633/com.sekspir.grind4gain V/NativeCrypto: SSL handshake aborted: ssl=0xdaa42da8: I/O error during system call, Connection reset by peer

我在这里错过了什么吗?我正在使用带有 Flutter 调试版本的真实 Android 设备。

这是 Firestore AppCheck Stats 看起来两个请求收入

但是在存储会话中没有任何请求失败或成功。

【问题讨论】:

  • 您能否确认您的Android日志级别设置为DEBUG级别及以上?这是为了确保DebugAppCheckProvider: Enter this debug secret into the allow list in the Firebase Console for your project: 123a4567-b89c-12d3-e456-789012345678 logcat 条目没有被过滤掉。

标签: flutter dart firebase-storage firebase-app-check


【解决方案1】:

您能否再次检查您是否正确 enabled the enforcement
需要使用 Firebase 存储解决方案。

您是在“PWA”模式还是“Native”模式下使用您的应用?
Recaptcha 可能是强制性的,具体取决于您的应用的分发方式。

  await FirebaseAppCheck.instance.activate(
    webRecaptchaSiteKey: 'recaptcha-v3-site-key',
  );

我不确定您在 Android Native 端实现了 appcheck-debug 依赖项。
由于它已经由 Flutter 库本身实现,因此您应该将其删除。

个人说明:我在某些设备上使用 FirebaseAppCheck 时遇到了问题,而它在其他设备上运行良好。
这个库仍处于测试阶段,我建议在生产中使用它之前等待。

【讨论】:

    猜你喜欢
    • 2023-01-31
    • 1970-01-01
    • 2019-07-07
    • 2014-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-07
    相关资源
    最近更新 更多