英文:
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://<database name>.firebaseio.com/Bucket&Code:<alphanumeric code>
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://<数据库名称>.firebaseio.com/Bucket_Code/<字母数字代码>
并且在您的规则中,您确保只有当您知道路径时才能访问它,以便您无法读取它上面的路径:
{
"rules": {
".read": false,
"Bucket_Code": {
"<字母数字代码>": {
".read": true
}
}
}
}
现在,为了能够访问数据,您需要知道整个路径 - 包括代码。一旦您知道路径(包括代码),您就可以访问数据。
多年来已经多次涵盖了这个主题,所以我建议您还要查看以下链接:
- https://stackoverflow.com/questions/53784606/firebase-database-share-data-when-uid-unknown/53784982#53784982
- https://stackoverflow.com/questions/75434711/firebase-realtime-database-security-rules-for-personal-app/75437785#75437785
- https://stackoverflow.com/questions/50083815/how-do-i-authenticate-my-firebase-with-just-a-string-key/50087317#50087317
- https://stackoverflow.com/questions/65993204/firebase-database-sending-payload-with-rest-request/65995490#65995490
- https://stackoverflow.com/questions/61984824/firebase-realtime-database-rules-for-secret-url-sharing
英文:
In cases like this, I recommend just treating the code as part of the path. So the path then becomes:
https://<database name>.firebaseio.com/Bucket_Code/<alphanumeric code>
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:
{
"rules": {
".read": false,
"Bucket_Code": {
"<alphanumeric code>": {
".read": 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:
- https://stackoverflow.com/questions/53784606/firebase-database-share-data-when-uid-unknown/53784982#53784982
- https://stackoverflow.com/questions/75434711/firebase-realtime-database-security-rules-for-personal-app/75437785#75437785
- https://stackoverflow.com/questions/50083815/how-do-i-authenticate-my-firebase-with-just-a-string-key/50087317#50087317
- https://stackoverflow.com/questions/65993204/firebase-database-sending-payload-with-rest-request/65995490#65995490
- https://stackoverflow.com/questions/61984824/firebase-realtime-database-rules-for-secret-url-sharing
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论