【问题标题】:What is different from "request.resource.auth" vs "request.auth" in Firestore security setting rule?Firestore 安全设置规则中的“request.resource.auth”与“request.auth”有什么不同?
【发布时间】:2021-05-20 08:13:26
【问题描述】:

今天,我正在阅读有关 Firestore 安全规则的内容,
我看到使用 **"request.resource.auth"** 和 **"request.auth"** 检查身份验证规则的情况。
我想知道与他们有什么不同?

以下是关于这些示例:
service cloud.firestore {
  match /databases/{database}/documents {
    // Allow any logged in user to view the public employee data
    match /employees/{emp_id} {
      allow read: if request.resource.auth != null
      // Allow only users with the custom auth claim of "Finance" to view
      // the employee's financial data
      match /private/finances {
        allow read: if request.resource.auth &&
          request.resource.auth.token.role == 'Finance'
      }
    }
  }
}

service cloud.firestore {
  match /databases/{database}/documents {
    // Allow the user to access documents in the "cities" collection
    // only if they are authenticated.
    match /cities/{city} {
      allow read, write: if request.auth != null;
    }
  }
}

谢谢!

【问题讨论】:

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


    【解决方案1】:

    您使用“request.resource.auth”引用的 Firestore 安全示例是自定义身份验证规则。基本上,它不是 Firestore 的一部分,它是请求资源中名为“auth”的字段,用于提供额外的标识。
    请问你是用什么语言读的?我通常用英语阅读文档,但是当我更改语言时(或者更准确地说,谷歌已经自动确定我肯定想用西班牙语阅读)我注意到有时会出现不一致甚至省略了一些重要的内容信息,可以而且应该报告。
    Here's 我在其中找到指定它是自定义字段的信息。

    让我知道这是否有帮助或是否需要更多说明。

    【讨论】:

      猜你喜欢
      • 2019-09-15
      • 2021-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-19
      相关资源
      最近更新 更多