没有更改我的 Firebase 可调用函数代码中的任何内容,但是重新部署了它们,现在他们突然开始拒绝我的应用程序中的所有函数调用,并出现如下所示的错误。在我准备好进行所需的更改之前,我不想使用 App Check。如何阻止我的可调用 (https.onCall) Firebase 函数拒绝无效的应用检查,而只拒绝无效的身份验证?
Failed to validate AppCheck token. FirebaseAppCheckError: Decoding App Check token failed. Make sure you passed the entire string JWT which represents the Firebase App Check token.
at FirebaseAppCheckError.FirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:44:28)
at FirebaseAppCheckError.PrefixedFirebaseError [as constructor] (/workspace/node_modules/firebase-admin/lib/utils/error.js:90:28)
at new FirebaseAppCheckError (/workspace/node_modules/firebase-admin/lib/app-check/app-check-api-client-internal.js:187:28)
at /workspace/node_modules/firebase-admin/lib/app-check/token-verifier.js:82:19
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
errorInfo: {
code: 'app-check/invalid-argument',
message: 'Decoding App Check token failed. Make sure you passed the entire string JWT which represents the Firebase App Check token.'
},
codePrefix: 'app-check'
}
Callable request verification failed: AppCheck token was rejected. {"verifications":{"app":"INVALID","auth":"VALID"}}
由于无效的 App Check 而拒绝所有请求的代码非常简单:const functions = require("firebase-functions");
const admin = require("firebase-admin");
admin.initializeApp();
exports.example = functions.https.onCall((data, context) => {
return "test";
}
包.json:"engines": {
"node": "12"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^9.10.0",
"firebase-functions": "^3.14.1"
},
最佳答案
我有同样的经历。文档说你应该像这样检查[1]:
if (context.app == undefined) {
throw new functions.https.HttpsError(
'failed-precondition',
'The function must be called from an App Check verified app.')
}
但是,根据我的经验,情况并非如此,当您将 App Check 添加到您的应用程序时,App Check 会立即开始执行。编辑:
此外,即使没有对我的代码进行任何检查,每当我调用我的一个函数时,我都可以在日志中看到这一点:
Callable request verification passed {"verifications":{"auth":"VALID","app":"VALID"}}
所以看起来 App Check 是自动发生的,至少在 Callable Functions 中是这样。如果您想在您的功能之一中绕过 AppCheck,您可能想要尝试使用 HTTP 功能(而不是 Callable)。[1] 来源 https://firebase.google.com/docs/app-check/cloud-functions
关于firebase - 应用程序检查 Firebase 可调用函数上不必要的强制执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68386179/