【问题标题】:Using User Claims in Firebase Storage rules在 Firebase 存储规则中使用用户声明
【发布时间】:2019-11-07 02:02:37
【问题描述】:

是否可以在 Firebase 存储规则中使用自定义声明? 看起来这些值无法从那里访问。

这是我的规则:

match /b/{bucket}/o {    
  match /{userId}/files/{fileName} {
    allow read: if request.auth.token.admin == true;
  }
}

这些规则会引发错误:

错误:simulator.rules 行 [13],列 [20]。属性管理员是 对象上未定义。

我之前是这样设置 userClaims 的:

await admin.auth().setCustomUserClaims(user.uid, {
        groupToken: 'abecadlo',
        admin: true
    });

【问题讨论】:

  • 您在 Firebase 控制台上使用过 Firebase 存储模拟器吗? Firebase 控制台上的 Firebase 存储模拟器无法使用自定义声明进行模拟。您可以尝试使用您的应用测试安全规则吗?
  • 是的 - it is possible。我不确定您为什么会收到该错误 - 除非您使用像 zkohi 询问的模拟器。

标签: firebase firebase-authentication firebase-storage firebase-admin firebase-security


【解决方案1】:

以下规则应该消除警告:

    match /b/{bucket}/o {    
      match /{userId}/files/{fileName} {
        allow read: if "admin" in request.auth.token && request.auth.token.admin == true;
      }
    }

【讨论】:

    猜你喜欢
    • 2019-07-20
    • 2018-07-03
    • 2020-07-20
    • 2017-08-11
    • 2018-06-05
    • 2017-01-25
    • 1970-01-01
    • 2016-12-19
    • 2020-10-03
    相关资源
    最近更新 更多