Firebase Flatter Firestore-权限被拒绝:缺少权限或权限不足
我在firestore数据库中设置了以下简单规则Firebase Flatter Firestore-权限被拒绝:缺少权限或权限不足,firebase,firebase-authentication,google-cloud-firestore,flutter,Firebase,Firebase Authentication,Google Cloud Firestore,Flutter,我在firestore数据库中设置了以下简单规则 service cloud.firestore { match /databases/{database}/documents { function isSignedIn() { return request.auth != null; } match /organisations/{orgID}/{document=**} { allow list, read, write: if isSi
service cloud.firestore {
match /databases/{database}/documents {
function isSignedIn() {
return request.auth != null;
}
match /organisations/{orgID}/{document=**} {
allow list, read, write: if isSignedIn() && request.auth.claims.organisation_uuid == orgID;
}
}
}
其目的是任何经过身份验证的用户都可以访问其组织中的所有文档。我希望用户能够访问的示例集合是tasks子集合,如下所示
"organisations": [
"$orgID": {
"tasks": [
"taskID1": {
...
},
"taskID2": {
...
},
]
}
用户正在使用如下所示的服务帐户使用自定义JWT令牌进行身份验证
{
"iss":"accountemail@db-name.iam.gserviceaccount.com",
"sub":"accountemail@db-name.iam.gserviceaccount.com",
"aud":"$correct-audience-string",
"iat":1532937868,
"uid":"e13e07a8-f7f2-4c7a-a02f-be729601e62e",
"exp":1532941468,
"claims":{
"organisation_uuid":"9cb3ebae-d16e-4898-a784-f0aac513fcb8"
}
}
上面的声明部分对应于my db安全规则中的request.auth.claims.organization_uuid==orgID规则。
firestore web控制台中模拟的单个文档请求可以正常工作,但使用Flatter cloud_store库构建的查询如下所示
Firestore.instance
.collection('organisations')
.document(technician.organisation_uuid)
.collection('tasks')
.where("assignee_uuid", isEqualTo: technician.uuid);
结果出现异常com.google.firebase.firestore.FirebaseFirestoreException:权限\被拒绝:权限缺失或不足。-
我无法确定我的规则有什么问题,因为该组织下的所有文档都应该由经过身份验证的用户访问。任何洞察都将不胜感激 因此,我认为这方面的问题在于。声明我的自定义令牌的一部分在请求对象上不可用,我将规则更新为以下内容,并且一切正常
service cloud.firestore {
match /databases/{database}/documents {
function isSignedIn() {
return request.auth != null;
}
function isInTheCorrectOrganisation(orgID){
return get(/databases/$(database)/documents/organisations/$(orgID)/technicians/$(request.auth.uid)).data.organisation_uuid == orgID;
}
match /organisations/{orgID}/{document=**} {
allow read, write: if isSignedIn() && isInTheCorrectOrganisation(orgID);
}
}
}
在我看来,自定义JWT令牌声明的评估方式似乎存在缺陷,或者我误读了文档,澄清一下就好了。我想知道我是否遇到了每个请求评估次数的限制``存在的最大数量,get,以及针对单个文档请求和查询请求的每个请求10的getAfter调用。20用于多文档读取、事务和批处理写入。之前的10限制也适用于每个操作```