我有一个聊天应用程序,用户可以在私有(private)聊天或群聊中发送照片。每个私聊或群聊都有一个唯一的聊天 ID:/images/<chat id>/image.jpg
如何保护对这些文件的访问,以便只有聊天成员才能查看它们?在Firebase database
我有一个结构如下的节点:/members/<chat id>/member1: true
.
这真的有必要吗,因为链接只发布到相应的聊天中?
任何授权用户都可以实际浏览保存在 Firebase storage
中的文件吗? ?或者这是设计阻止的?
最佳答案
永恒的问题。它讨论了几个地方( Google Group , Storage Docs , Github Gist ),但 TL;DR 是:目前,没有办法从另一个服务的规则中读取数据。对于服务,您可以执行以下两项操作之一:
- 在自定义 token 中传递组信息
- 在服务中的自定义元数据中传递群组信息
一个这样的例子:
// Allow reads if the group ID in your token matches the file metadata's `owner` property
// Allow writes if the group ID is in the user's custom token
match /files/{groupId}/{fileName} {
allow read: if resource.metadata.owner == request.auth.token.groupId;
allow write: if request.auth.token.groupId == groupId;
}
关于firebase - 如何限制组成员对文件的访问?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41086446/