我的Firestore中有以下规则
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId}/{documents=**} {
// Only the authenticated user who authored the document can read or write
allow read: if request.auth.uid == userId;
allow write;
}
}
}
这似乎不起作用,我正在使用Rest API获取我调用的身份验证数据:https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyPassword?key=[API_键]
经过身份验证后,我们获得idToken并作为下一个URL的授权标头传递https://firestore.googleapis.com/v1beta1/projects//databases/(默认)/文档/用户
用户集合将id作为文档名,而值只是一堆假密钥。
当我运行客户端时,我得到的错误是
{u'status':u'PERMISSION\u DENIED',u'message':u'Missing or uncipled permissions',u'code':403}
如果我硬编码userid的值,它就会工作。因此,由于某些原因,{userid}中返回的值似乎与UID不匹配。
有人能帮我解释一下为什么会这样吗?
谢谢公羊
您不需要文档=**选择器
service cloud.firestore { match /databases/{database}/documents { // dissallow all access match /{documents=**} { allow read, write: if false; } // Make sure the uid of the requesting user matches name of the user // document. The wildcard expression {userId} makes the userId variable // available in rules. match /users/{userId} { allow read, update, delete: if request.auth.uid == userId; allow create: if request.auth.uid != null; } } }
https://firebase.google.com/docs/firestore/security/rules-conditions