guc*_*pir 17 dart flutter firebase-storage firebase-app-check
我的应用程序从今天开始正常工作。我已经在我的 Android Flutter 应用程序中包含了 Firebase Storage,之后它就可以工作了,今天我突然收到 AppCheck 错误。我没有在我们的项目中包含应用程序检查,或者没有在设置中强制执行。之后,我遵循初始化 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)
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的 main():
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
await FirebaseAppCheck.instance.activate();
runApp(MyApp());
}
Run Code Online (Sandbox Code Playgroud)
我还将其添加到我的 app/build.gradle 中
dependencies {
implementation 'com.google.firebase:firebase-appcheck-debug:16.0.0-beta01'
}
Run Code Online (Sandbox Code Playgroud)
当我向 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
Run Code Online (Sandbox Code Playgroud)
我在这里错过了什么吗?我正在使用带有 flutter debug 版本的真实 Android 设备。
Can you double check that you correctly enabled the enforcement ?
It is required to work with Firebase Storage solutions.
Are you using your app in "PWA" mode or in "Native" mode ?
The Recaptcha may be mandatory depending on how your app is distributed.
await FirebaseAppCheck.instance.activate(
webRecaptchaSiteKey: 'recaptcha-v3-site-key',
);
Run Code Online (Sandbox Code Playgroud)
I'm not sure about your implementation of the appcheck-debug dependency on the Android Native side.
Since it's already implemented by the Flutter library itself, you should remove it.
Personal note : I had troubles with FirebaseAppCheck on some devices, while it was working perfectly on other devices.
This library is still in beta and I would recommend to wait before using it in production.