【发布时间】:2020-03-27 05:08:37
【问题描述】:
在 Cloud Firestore 中,我有一个文档集合,其中包含一个数组字段,其中包含应该对该文档具有读取权限的所有用户。我简化的安全规则是:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /collection_name/{document=**} {
allow read: if request.auth.uid in request.resource.data.listOfIds.toSet();
}
}
}
一个示例简化文档是:
{
listOfIds: ["uid1", "uid2"]
}
使用规则模拟器执行获取,读取按预期工作。但是,使用 Android API 执行类似的查询会返回权限被拒绝错误。我想我以与规则相同的方式限制我的查询(这是 Firestore 的 requirement;它不会过滤掉用户无法为您阅读的文档)。
firestoreClient.collection("collection_name")
.whereArrayContains("listOfIds", firebaseUid)
.get()
.addOnCompleteListener(...);
【问题讨论】:
标签: android google-cloud-firestore firebase-security