【问题标题】:Firebase: Authenticated user with full permissions gets PERMISSION DENIED on rootFirebase:具有完全权限的经过身份验证的用户在 root 上获得 PERMISSION DENIED
【发布时间】:2017-11-05 14:25:42
【问题描述】:

在 Firebase 控制台中设置规则:

{
  "rules": {
    ".read": true,
    ".write": true
  }
}

在 Chrome 控制台中运行:

> firebase.database().ref().set('foo');

Firebase 控制台的数据库选项卡现在反映 foo

在 Firebase 控制台中设置规则:

{
  "rules": {
    ".read": "auth != null",
    ".write": "auth != null"
  }
}

在 Chrome 控制台中运行:

> firebase.auth().signInAnonymously()
< A {W: 1, sa: undefined, u: null, oa: null, fb: nul…}
> firebase.database().ref().set('bar');
Uncaught (in promise) Error: PERMISSION_DENIED: Permission denied

Firebase 设置为允许匿名用户和 Google 用户,当我尝试读取或写入时,这两个用户都会获得 PERMISSION DENIED。

编辑

我在这里添加了一个示例项目:

https://github.com/formido/react-firebaseui-web-stackoverflow-question

如果我将规则设置为:

{
  "rules": {
    ".read": "auth != null",
    "44358340": { ".write": true }
  }
}

...并登录,控制台将打印Timestamp written

如果我将规则设置为:

{
  "rules": {
    ".read": "auth != null",
    "44358340": { ".write": "auth != null" }
  }
}

...并登录,控制台将打印 PERMISSION DENIED。

我知道的代码中最相关的部分是:

  componentDidMount() {
    firebase.auth().onAuthStateChanged((user) => {
      if (user) {
        const ref = firebase.database().ref("/44358340");
        if (user) {
          const timestamp = firebase.database.ServerValue.TIMESTAMP;
          ref.set(timestamp).then((error) => {
            if (error) {
              console.error(error);
            }
            else {
              console.log('Timestamp written');
            }
          });
        }
      }
      this.setState({loading: false, user});
    });
  }

它托管在亚马逊服务器上。我想也许我必须将 AUTH_DOMAIN 设置为 AWS 主机,但这并没有什么不同。

【问题讨论】:

  • 你的代码是否附加了一个监听器?
  • 有一个onAuthStateChanged 监听器,如果用户更改,它会尝试以与上述相同的方式设置数据库。它也获得了一个被拒绝的权限,这是开始这个​​探索的最初问题。
  • 请您分享更多代码,以便更轻松地检查您的侦听器的确切添加位置。问题可能在于服务器通信延迟。
  • 为我工作:jsbin.com/qiqezip/1/edit?html,js,output 与规则 "44358340": { ".write": "auth != null" }。如果您仍然遇到问题,请创建一个类似的 jsbin 来重现这些问题。
  • 是的,这适用于我的凭据。至少现在我有一个最小的例子来显示我的帐户工作并证明数据库写入是如何工作的。不过,我不知道如何协调我的 Chrome 控制台日志。

标签: reactjs firebase firebase-realtime-database firebase-authentication firebase-security


【解决方案1】:

这是一个错误。见discussion starting here

Fix here,它部署在Firebase 4.1.2

【讨论】:

    猜你喜欢
    • 2021-10-14
    • 1970-01-01
    • 2019-10-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-17
    • 2020-06-03
    • 2019-06-28
    相关资源
    最近更新 更多