【发布时间】:2018-10-08 05:34:32
【问题描述】:
我的数据大致如下:
/databases/schools/{schoolId}/faculty
/students
/etc
我有一群人的帐户上有 customClaim“schoolId”。我只希望他们能够访问他们所属学校的教师、学生等。尝试了多次迭代这个规则,最新的一个是
service cloud.firestore {
match /databases/schools/{document} {
match /{doc=**} {
allow read, write: if user.token.schoolId == document;
}
}
}
其他迭代包括:
service cloud.firestore {
match /databases/schools/{document} {
allow read, write: if user.token.schoolId == document;
}
}
和
service cloud.firestore {
match /databases/schools {
match /{document=**} {
allow read, write: if user.token.schoolId == document;
}
}
}
或
service cloud.firestore {
match /databases/{database}/documents {
match /{$document} {
allow read, write: if resource.id == user.token.schoolId;
}
}
}
感觉这应该是一件相当简单的事情,但我无法弄清楚(我正在进行第 12 次迭代)
我想我知道最后一个不起作用,因为如果我尝试获取 /databases/schools/school1/faculty/abc123 那么 resource.id 实际上是指 abc123 而不是 school1。
当我解码令牌时,示例用户如下所示:
uid: "gobblygook"
displayName: null
photoURL: null
email: "test-email@yopmail.com"
emailVerified: true
phoneNumber: null
isAnonymous: false
apiKey: "{apikey}"
appName: "[DEFAULT]"
authDomain: "{mydomain}.firebaseapp.com"
lastLoginAt: "1538972960000"
createdAt: "1538868952000"
schoolId: "school1"
【问题讨论】:
标签: firebase google-cloud-firestore firebase-security