【问题标题】:is there a way to authenticate user role in firebase storage rules? [duplicate]有没有办法在 Firebase 存储规则中验证用户角色? [复制]
【发布时间】:2017-01-04 08:57:50
【问题描述】:

我正在尝试根据用户角色限制 Firebase 存储。

Database:
    users
        <uid>
            admin=false
            ... ... ...

我正在尝试在 firebase 存储中使用以下类型的规则:

root.child('users').child(auth.uid).child('user').child('admin').val() == true

将此添加到写入规则后,我的访问被拒绝。

谢谢。

【问题讨论】:

  • Firebase 存储安全规则不能引用数据库中的数据。请参阅 this answerthis one 了解如何执行基于角色的安全性等操作。
  • 谢谢弗兰克。它有点老套,但我想我现在能做的就这些了。
  • 您可以使用“自定义声明”,您必须在其中一个 Firebase 函数中设置自定义声明,但它们会被传递到 Firebase 存储。

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


【解决方案1】:

正如 Frank van Puffelen 在评论中指出的那样:

function isAdminUser() {
    return request.auth.uid in {
        "yaddayadddayaddUserIDKey":"User Name1"
    };
}

service firebase.storage {
    match /b/<appName>.appspot.com/o {
        match /{allPaths=**} {
            allow read;
            allow write: if request.auth != null && isAdminUser();
        }
   }
}

【讨论】:

  • is admin 函数似乎是硬编码值。这是目前唯一的选择吗?
  • 很遗憾,目前只有这些。
猜你喜欢
  • 1970-01-01
  • 2020-11-02
  • 2023-03-21
  • 1970-01-01
  • 1970-01-01
  • 2018-08-24
  • 2019-08-15
  • 2016-11-23
相关资源
最近更新 更多