小编aba*_*ker的帖子

适用于firebase中受保护内容的授权规则

是否有针对firebase应用程序中受保护内容的适当授权规则的最佳实践方法

  • 特别使用firepad
  • 受保护的内容我指的是用户创建文档的位置,并且只与某些其他用户共享.
  • 此外,我需要能够查询firebase以查找我有权访问的所有文档(我创建的文档和其他用户与我共享的文档)

到目前为止我的一些研究:

方法1:秘密URL

  • 我需要知道能够查看/编辑文档的URL

  • 不是真正的授权,因为任何有权访问该URL的登录用户都可以编辑/修改它.

  • 无法索引我有权访问的所有文档

方法2:使用firebase授权规则将用户添加到文档,并在读/写之前检查用户是否为document.users.

取自: Firebase中的受保护内容可能吗?

{

"documents": {

   "$documents_id": {

       // any friend can read my post

       ".read":  "auth.id === data.child('owner').val() || root.child('users/'+data.child.owner.val()+'/users/'+auth.id).exists()",

       // any friend can edit my post
       ".write": "auth.id === data.child('owner').val() || root.child('users/'+data.child.owner.val()+'/users/'+auth.id).exists()"

   },

   users:{

   // List of user.ids that have access to this document

   }

}

}
Run Code Online (Sandbox Code Playgroud)

优点:

  • 正确的授权/认证.只有已获得访问权限的经过身份验证的用户才能查看/编辑.

缺点:

  • 无法查询允许用户编辑的所有文档(我拥有或已与我共享的文档)(这个假设是否正确?)

方法3: Firebase授权规则(方法2),以及每个用户都可以访问的document_ids数组的冗余用户存储.此用户存储仅用于查询用户有权访问的所有文档.即:

{
"documents": {
   "$documents_id": {
       // any friend can read my post
       ".read":  "auth.id === …
Run Code Online (Sandbox Code Playgroud)

security authentication authorization firebase firepad

26
推荐指数
1
解决办法
9898
查看次数