【问题标题】:Firebase Storage Wildcard Rules with Custom tokens带有自定义令牌的 Firebase 存储通配符规则
【发布时间】:2019-03-15 15:57:48
【问题描述】:

由于某种原因,我无法让通配符在带有自定义令牌的路径中工作。 用户具有分配的自定义令牌,例如 admin: trueySWLb8NSTj9sur6n2CbS: true

service firebase.storage {
  match /b/{bucket}/o {
        match /conferences/{confId}/sponsors/{sponsId=**} {
        allow read: if request.auth.uid != null
        allow write: if request.auth.token.confId == true
    }
  }
}

我正在尝试从客户端写入 /conferences/ySWLb8NSTj9sur6n2CbS/sponsors/whatever.jpeg,但访问被拒绝。

如果我现在更改为以下内容,它可以正常工作。

service firebase.storage {
  match /b/{bucket}/o {
        match /conferences/{confId}/sponsors/{sponsId=**} {
        allow read: if request.auth.uid != null
        allow write: if request.auth.token.admin == true
    }
  }
}

我什至通过将自定义令牌更改为ySWLb8NSTj9sur6n2CbS: "ySWLb8NSTj9sur6n2CbS" 进行了测试,然后尝试以下操作但未成功并被拒绝访问!

service firebase.storage {
  match /b/{bucket}/o {
        match /conferences/{confId}/sponsors/{sponsId=**} {
        allow read: if request.auth.uid != null
        allow write: if request.auth.token.confId == confId
    }
  }
}

我感觉通配符由于某种原因没有被选中,还是我在这里忽略了某些东西? 在我发现的文档中:https://firebase.google.com/docs/storage/security/user-security?authuser=0

【问题讨论】:

    标签: firebase firebase-storage firebase-security


    【解决方案1】:

    所以我发现它的另一种方法是出于某种奇怪的原因。 我已经以数组的形式为用户分配了一个自定义声明。在那个数组中你有 confId。所以我检查相关的 confId 是否在该数组中。

    service firebase.storage {
      match /b/{bucket}/o {
            match /conferences {
            match /{confId}/sponsors/{sponsorId} {
            allow read: if confId in request.auth.token.userEvents
            allow write: if confId in request.auth.token.adminEvents
          }
        }
      }
    }
    

    【讨论】:

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