【发布时间】:2021-08-11 09:41:34
【问题描述】:
我有一个简单的 Firebase 托管网络应用程序(基于 Vue 应用程序),它调用 Firebase 函数(谷歌云函数):
import firebase from "firebase/app";
import "firebase/functions";
firebase.initializeApp(firebaseConfig);
let functions = firebase.app().functions("us-west4");
let testFunction = functions.httpsCallable("testFunction");
及对应函数index.js文件:
const functions = require("firebase-functions");
exports.testFunction = functions.region("us-west4").https.onCall(async (data, context) => {
console.log("Very important things here");
return {"response": "data"};
});
从安全角度来看是不是可以
- 仅允许来自我的域名(Firebase 托管)
myhostedapp.web.app的此调用 - 检查我的 JS 应用在请求期间提供的任何类型的身份验证(例如令牌)?
我已尝试访问 context.auth 属性 (see docs),但似乎需要某种服务帐户,并且在从 Firebase 托管 Web 应用程序调用时无法使用。
基本上,我不希望我的函数可公开访问(通过触发 url 进行简单调用),因此任何保护 Firebase Hosting + Functions 的建议或最佳实践将不胜感激。
【问题讨论】:
-
关于云功能的“允许未经身份验证”部分,请查看this answer,了解为什么需要这样的信息。注意:我还没有用新的App Check 的信息更新它。
标签: firebase firebase-authentication google-cloud-functions firebase-security firebase-hosting