【问题标题】:how can i restrict access to firestore database to only requests coming from specific domain?如何限制对 Firestore 数据库的访问仅限来自特定域的请求?
【发布时间】:2021-11-12 16:16:37
【问题描述】:

这里有一个安全规则可以限制特定用户的访问:restrict access to specific users

弗兰克的回答真的很有帮助而且很直接,但是如果我不使用 Firestore 身份验证怎么办?!

我想要实现的只是授予对仅来自我的域的请求的访问权限......只是域,没有身份验证......所以没有人可以使用邮递员例如向我的 firestore 数据库发送 GET 或 POST 请求。

有没有办法可以这样说:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.origin.matches(/<https://myCompany.com>/);
    }
  }
}

任何帮助将不胜感激。

【问题讨论】:

    标签: firebase google-cloud-firestore firebase-security


    【解决方案1】:

    没有办法限制来自特定域的请求,这实际上也很容易被欺骗。像 Firebase App Check 这样的东西会有所帮助,但 Firestore 尚不可用。

    限制谁可以访问数据库的常用方法是:

    1. 要求用户登录 Firebase 身份验证
    2. 要求他们验证电子邮件地址。
    3. 在安全规则中验证request.auth.token.email 的电子邮件地址。

    另见:

    【讨论】:

    • 我想我可以应用一个简单的解决方法来实现我想要的特定域目标,我们将为我们的员工“employee1@myCompany.com”创建业务电子邮件,然后我们要求他们登录到 Firebase身份验证,然后在 Firestore 的安全规则中我们可以执行以下检查:允许读取,写入 if:“auth.token.email_verified == true && auth.token.email.matches(/.*@myCompany.com$/)”.. ..谢谢弗兰克,祝你有美好的一天:)
    • 是的,方法差不多。
    猜你喜欢
    • 2014-08-13
    • 1970-01-01
    • 2021-08-22
    • 2020-04-26
    • 2018-09-16
    • 2013-08-09
    • 2020-12-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多