我使用Stripe付款.为此,我在Firestore中有以下数据模型:
Users/{userId}/payments/{document}
Run Code Online (Sandbox Code Playgroud)
每个{document}都是一个看起来像这样的对象:
{
amount: 55
token: {...}
charge: {...}
}
Run Code Online (Sandbox Code Playgroud)
用户必须能够编写该token字段(这是传递给服务器的内容),但我不希望用户能够编写该charge字段.
目前我的规则允许任何用户读取和写入此文档:
match /payments/{documents} {
allow read, write: if request.auth.uid == userId;
}
Run Code Online (Sandbox Code Playgroud)
什么Firestore规则将实现我所期望的安全性?
stripe-payments firebase firebase-security google-cloud-firestore
我正在使用 firebase (firestore) 开发一个网站,该网站向基于角色的用户显示文章。
所以数据库保存了文章的集合
qlt0mPbTBt1rQcrx1HJR: {
title: 'Article 1'
description: 'Lorem ipsum, dolor sit amet consectetur adipisicing elit.'
secretInfo: 'secret text for partners only...'
},
lrTk2ybMLiDuUw6pcwll: {
title: 'Article 2'
description: 'Lorem ipsum, dolor sit amet consectetur adipisicing elit.'
secretInfo: 'secret text for partners only...'
}
Run Code Online (Sandbox Code Playgroud)
部分文章字段是公开的(例如标题/描述),应该由所有用户查看,同一文章的其他一些字段(例如 secretInfo)是私有的,只能由具有特权角色的特定用户(合作伙伴/管理员等)查看'……)。
我知道可以根据特定规则“允许读取”来自 firebase 的集合/文档 - 正如他们的文档中所描述的那样
service cloud.firestore {
match /databases/{database}/documents {
// Only the authenticated user who authored the document can read or write
allow read, write: if request.auth.uid == resource.data.author; …Run Code Online (Sandbox Code Playgroud) 我有多个文档。我的问题是我无法获取修改的特定数据,我正在获取完整的文档。
db.collection("employees").whereEqualTo("OID", OID)
.addSnapshotListener(new EventListener<QuerySnapshot>() {
@Override
public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
if (e != null) {
Log.w(TAG, "listen:error", e);
return;
}
for (DocumentChange dc : snapshots.getDocumentChanges()) {
switch (dc.getType()) {
case ADDED:
//Here i am getting full newly added documents
break;
case MODIFIED:
//here i am getting which is modified document,ok fine...,But i want to get only the filed which i modified instance of getting full documents..
break;
case REMOVED:
break;
}
}
}
}); …Run Code Online (Sandbox Code Playgroud) 我正在尝试实施安全规则来限制用户只能访问文档中的特定字段。我的数据结构是这样的:
document {
name: John,
dob: 1994,
email: john@hotmail.com
}
Run Code Online (Sandbox Code Playgroud)
我想将name字段限制为read, write by owner;dob字段到read by owner, create by owner; email到read by owner, update by owner
我阅读了文档,似乎我只能使用安全规则来控制特定文档的访问。它没有提到任何允许访问特定字段的内容。我应该做什么才能允许访问文档中的特定字段?