【问题标题】:Firebase authenticated user but no permissionFirebase 经过身份验证的用户,但没有权限
【发布时间】:2021-10-14 09:30:09
【问题描述】:

我有以下规则:

rules": {
    ".read": "( auth.token.email.matches(/.*@domain1.com$/) || auth.token.email.matches(/.*@domain2.com$/) || auth.token.email.matches(/.*@domain3.com$/) ) && auth.token.email_verified == true",
    ".write": "( auth.token.email.matches(/.*@domain1.com$/) || auth.token.email.matches(/.*@domain2.com$/) || auth.token.email.matches(/.*@domain3.com$/) ) && auth.token.email_verified == true"
}

我正在尝试使用 firebase 实时数据库规则游乐场来测试为什么在用户在我的应用上通过身份验证后,对 firebase 实时的任何调用都会返回错误:

permission_denied at /anyDocument: Client doesn't have permission to access the desired data.

我的数据库没有任何文档权限,只要用户通过身份验证,他们就应该可以访问其中的任何和所有文档。我正在使用以下身份验证负载:"

{
  "uid": "",
  "token": {
    "sub": "",
    "aud": "keane-docc-dev",
    "email": "email@domain1.com",
    "email_verified": true,
    "firebase": {
      "sign_in_provider": "password"
    }
  }
}

在规则模拟上,它可以工作,但在应用程序上我得到权限错误。

我的登录密码是:

import { AngularFireAuth } from '@angular/fire/auth';

export class SignInComponent {
signIn(email: string, password: string) {    
    this.angularFireAuth
      .signInWithEmailAndPassword(email, password)
      .then((userCredential) => {
        // I do some stuff here
      })
      .catch((error) => {
        this.authErrorHandler(error);
      });
  }
}

一切正常,用户通过身份验证,令牌 ID 与预期相符,但权限失败。

在我的 app.component 上,我使用标准方法进行初始化。我正在使用angular/fire 并根据文档初始化模块。有什么我想念的想法吗?

额外信息: 此处的一些其他问题指出,在执行实时数据库查询时,用户可能尚未通过身份验证。我认为这几乎不是我的情况,因为一旦我在 firebase 上进行身份验证,我就会使用该令牌通过 API 进行身份验证,该 API 使用 firebase 令牌检查谁是我的用户,并且该令牌由 API 与 Firebase SDK 核对到firebase(我的项目在 GCP 上运行)。

这一切的开始是因为我不再使用 ngx-auth-firebaseui,那个包曾经做过我的 firebase 初始化,现在我正在使用 AngularFire,但它不起作用。

【问题讨论】:

    标签: angular firebase-realtime-database


    【解决方案1】:

    就我而言,问题与过时版本的 firebase 和 angular/fire 有关。他们会查询、验证,但在规则上失败。可能有一个新版本,有效载荷的对象发生了变化。

    一旦我更新了两者,错误就消失了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-23
      • 2019-06-28
      • 1970-01-01
      • 2018-08-18
      • 2017-11-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多