我们可以根据秘密代码来限制在Firebase中对路径的访问吗?

huangapple go评论47阅读模式
英文:

Can we limit access to a path in Firebase based on a secret code?

问题

我一直在思考是否可以使用Firebase实现这个功能
假设我请求Firebase实时数据库

https://<数据库名称>.firebaseio.com/Bucket&Code:<字母数字代码>

所以每当我想要访问Firebase时,只有当有代码时才能读取和写入
请注意,这与经过身份验证的Firebase RT数据库不同

如果可能的话,如何实现?
提前感谢

我尝试使用条件,但始终会在变量上出现错误。

英文:

I’ve been thinking if this is possible with Firebase
Suppose I Request Firebase Realtime Database

https://&lt;database name&gt;.firebaseio.com/Bucket&amp;Code:&lt;alphanumeric code&gt;

So whenever I want to Access Firebase it should Only give access to read & Write if the code is there
Please Note this is different from Aunthicated Firebase RT Database

If it is possible then How to make it?
Thanks in Advance

I Tried using conditions but it was always giving an error on the variables

答案1

得分: 1

在这种情况下,我建议将代码视为路径的一部分。因此,路径变为:

https://&lt;数据库名称&gt;.firebaseio.com/Bucket_Code/&lt;字母数字代码&gt;

并且在您的规则中,您确保只有当您知道路径时才能访问它,以便您无法读取它上面的路径:

{
  &quot;rules&quot;: {
    &quot;.read&quot;: false,
    &quot;Bucket_Code&quot;: {
      &quot;&lt;字母数字代码&gt;&quot;: {
        &quot;.read&quot;: true
      }
    }
  }
}

现在,为了能够访问数据,您需要知道整个路径 - 包括代码。一旦您知道路径(包括代码),您就可以访问数据。

多年来已经多次涵盖了这个主题,所以我建议您还要查看以下链接:

英文:

In cases like this, I recommend just treating the code as part of the path. So the path then becomes:

https://&lt;database name&gt;.firebaseio.com/Bucket_Code/&lt;alphanumeric code&gt;

And in your rules you ensure that you can only access the path if you know it, so that you can't read the path above it:

{
  &quot;rules&quot;: {
    &quot;.read&quot;: false,
    &quot;Bucket_Code&quot;: {
      &quot;&lt;alphanumeric code&gt;&quot;: {
        &quot;.read&quot;: true
      }
    }
  }
}

Now in order to be able to access the data, you need to know the entire path - including the code. And once you know the path (including the code), you have access to the data.

This topic has been covered a few times over the years, so I recommend also checking out:

huangapple
  • 本文由 发表于 2023年6月26日 00:12:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76551342.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定