Javascript Firebase集合的唯一IP写入权限
假设我有一系列文章:Javascript Firebase集合的唯一IP写入权限,javascript,angularjs,firebase,angularfire,Javascript,Angularjs,Firebase,Angularfire,假设我有一系列文章: https://example.firebaseio.com/articles/$key 我想在文章中添加查看计数器和当前用户中心子项 https://example.firebaseio.com/articles/$key/viewCounter https://example.firebaseio.com/articles/$key/currentUsersCounter 每当用户滚动到下一篇文章时,我都会执行一个函数: var currentArticle = f
https://example.firebaseio.com/articles/$key
我想在文章
中添加查看计数器
和当前用户中心
子项
https://example.firebaseio.com/articles/$key/viewCounter
https://example.firebaseio.com/articles/$key/currentUsersCounter
每当用户滚动到下一篇文章时,我都会执行一个函数:
var currentArticle = function(key){
//key == index of the article
//This is where I want to increment the `viewCounter` and `currentUsersCounter`
}
很明显,我不希望任何人给那两个孩子写信
- 我如何扩展我的安全规则,目前(黑名单所有写入)为仅针对这些特定集合的白名单写入
- 在这些白名单集合的安全规则中,如何将写入限制为唯一的IP地址?(如有可能)
{
"rules": {
".read": true,
".write": "auth.email == 'example@gmail.com'"
}
}
您不能以保护数据完整性的方式执行此操作(即确保计数实际上是准确的),因为如果您授予对这些字段的写访问权,客户端可以写入它想要写入的任何值 但是,通过使用安全规则中的变量,您可以仅为这些特定子级提供细粒度读/写访问:
{
“条款”:{
“$key”:{
“查看计数器”:{
“.write”:正确,
.validate:“newData.isNumber()&&newData.val()==data.val()+1”
},
“$其他”:{
“.write”:“auth.email==”example@gmail.com'"
}
}
}
}
不可能基于IP地址进行任何过滤。您需要使用来自受信任服务器代码的密码来执行此操作,如评论中所建议的。使用服务器端代理隐藏firebase URL,并对用户活动执行无限制的身份验证/验证。@dandavis是的,如果归结到这一点,我想我必须这样做。我希望通过Firebase API可以利用某种“神奇”的帮助函数。你能用它自己的规则将这些信息放在不同的集合中吗?