【问题标题】:Firebase User Security SimulationFirebase 用户安全模拟
【发布时间】:2018-02-25 23:20:48
【问题描述】:

我在这里真的很摸不着头脑,我一直在尽可能多地阅读许多其他案例。我是 Firebase 的新手,但对它有所了解。我想将数据库的某些记录限制为某些用户。所以这是我的 JSON:

  "accounts" : {
    "13asdf313" : {
      "dog" : "bacon",
      "email" : "luis@fakeemail.com",
      "first" : "luis",
      "last" : "xxxx"
    },
    "HlELrrGDbiMKgxxxx" : {
      "name" : "Luis"
    },
    "anthony" : {
      "email" : "anthony@fakeemail.com",
      "last" : "xxxx",
      "name" : "anthony"
    },
    "jpSq6UzX0mcAvExxxx" : {
      "name" : "anthony"
    }
  }

以下是根据我阅读的内容制定的规则:

{
  "rules": {
    "accounts":{

      "$uid":{
        ".read": "auth.uid == $uid",
        ".write": "auth.uid == $uid"
      }
    },

  }


}

在模拟器中,我使用了底部条件(我什至将 /accounts 放在位置字段中)。我使用了 UID:HlELrrGDbiMKgxxxx,直接从 Firebase 帐户列表复制。

这总是失败

我做错了什么?

【问题讨论】:

    标签: firebase firebase-realtime-database firebase-security firebase-console


    【解决方案1】:

    您必须在 Location 字段中插入 accounts/HlELrrGDbiMKgxxxx

    否则您会尝试访问整个数据库(标准位置是root,它覆盖整个数据库)。您的规则只是为子 accounts/$uid 设置的,并且要访问它,来自身份验证的用户 ID 和数据库中的子位置必须匹配。

    【讨论】:

    • oooooh,所以如果我通过 URL 查询,我需要添加 accounts/ 以获取所有具有 哈希的记录?
    • 是的,但这应该是有道理的。我的意思是,如果您想访问用户帐户数据并且用户已登录,则会为您提供必要的信息。在 JS 中,查询看起来像。 root.child(accounts/${auth.uid}).once('value') 这应该返回完整的用户条目。
    猜你喜欢
    • 2014-09-30
    • 2021-05-11
    • 2015-05-30
    • 1970-01-01
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-03
    相关资源
    最近更新 更多