对我的应用程序和云功能执行强制应用程序检查不会阻止来自外部的呼叫

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

我在 iOS 应用程序中使用 Firebase Cloud Functions。我想使用 Firebase App Check 来保护它们。我执行了“入门”指南中的所有步骤 - 包括应用程序检查框架、实现了应用程序证明所需的代码、添加了应用程序证明权利。

我的函数使用 Express。我还在那里强制执行了应用程序检查:

exports.myfunc = functions
  .runWith({enforceAppCheck: true})
  .https.onRequest(app);

但它似乎根本不起作用。从我的应用程序调用时,我的函数按预期工作。但是,我在 Cloud Functions 控制台中没有看到“可调用请求验证”日志。我能够在我的应用程序之外成功调用我的函数 - 从我的桌面上使用curl。

如何诊断问题出在哪里?

ios firebase express google-cloud-functions firebase-app-check
1个回答
0
投票

我需要在客户端和后端使用“可调用”云函数才能使 AppCheck 正常工作。我认为文档中对此强调得不够。

在客户端

try await functions.httpsCallable("foo").call(params)  // AppCheck works

let url = URL(string: "https://us-central1-myproject.cloudfunctions.net/foo")
var request: URLRequest = .init(url: url)
try await URLSession.shared.data(for: request)         // AppCheck doesn't work

在后台

exports.foo = functions
  .runWith({enforceAppCheck: true})
  .https.onCall((data, context) => {     // AppCheck works
});

const app = express();
exports.foo = functions
  .runWith({enforceAppCheck: true})
  .https.onRequest(app);                 // AppCheck doesn't work
© www.soinside.com 2019 - 2024. All rights reserved.