由于某种原因,我无法使通配符在具有自定义标记的路径中工作。
用户已分配了自定义令牌,例如admin: true
和ySWLb8NSTj9sur6n2CbS: true
service firebase.storage {
match /b/{bucket}/o {
match /conferences/{confId}/sponsors/{sponsId=**} {
allow read: if request.auth.uid != null
allow write: if request.auth.token.confId == true
}
}
}
我正尝试从客户端写到/conferences/ySWLb8NSTj9sur6n2CbS/sponsors/whatever.jpeg,但是访问被拒绝。
如果我现在更改为以下内容,它将正常工作。
service firebase.storage {
match /b/{bucket}/o {
match /conferences/{confId}/sponsors/{sponsId=**} {
allow read: if request.auth.uid != null
allow write: if request.auth.token.admin == true
}
}
}
我甚至通过将自定义令牌更改为ySWLb8NSTj9sur6n2CbS: "ySWLb8NSTj9sur6n2CbS"
,然后尝试以下操作均未成功并拒绝访问来对它进行测试!
service firebase.storage {
match /b/{bucket}/o {
match /conferences/{confId}/sponsors/{sponsId=**} {
allow read: if request.auth.uid != null
allow write: if request.auth.token.confId == confId
}
}
}
我感到通配符由于某种原因未被使用,或者我在这里忽略了什么? 在文档中,我发现:https://firebase.google.com/docs/storage/security/user-security?authuser=0
答案 0 :(得分:0)
所以我发现围绕它的另一种方法是出于某种奇怪的原因。 我已经以数组形式向用户分配了自定义声明。在该数组中,您有confId。所以我检查相关的confId是否在该数组中。
service firebase.storage {
match /b/{bucket}/o {
match /conferences {
match /{confId}/sponsors/{sponsorId} {
allow read: if confId in request.auth.token.userEvents
allow write: if confId in request.auth.token.adminEvents
}
}
}
}