ios - 带有 Firebase Id 令牌的 Firestore REST API
问题描述
我正在尝试使用从Auth SDK(ios,但实际上我将FirebaseAuth用于osx,这就是为什么除了使用REST之外我别无选择,因为没有FirebaseFirestore对osx的支持)在firestore创建新文档)。
规则是
service cloud.firestore {
match /databases/{database}/documents {
match /places {
allow create, update, delete, read: if true;
}
}
}
用于检索令牌
Auth.auth().currentUser?.getIDTokenForcingRefresh(true, completion ..
在我将令牌作为字符串并将其放入标头 Authorization: Bearer MY_RETRIEVED_TOKEN 之后
链接我请求
https://firestore.googleapis.com/v1beta1/projects/MYPROJECTID/databases/(default)/documents/places?fields=fields&documentId=kk&key=API_KEY_FOR_WEB_APP_FROM_FIREBASE_PROJECT_SETTING
所以在这里我从 Firebase 项目设置为 Web 传递密钥
此 POST 请求的正文
{
"fields": {
"nn": {
"stringValue": "hhh"
}
}
}
但最后我得到了 403 作为回应。
{
"error": {
"code": 403,
"message": "Missing or insufficient permissions.",
"status": "PERMISSION_DENIED"
}
}
已经打破了我的想法,试图找到一个错误。提前致谢!
解决方案
几天前我遇到了同样的问题。
您应该尝试修改您的规则,如下面的代码:
service cloud.firestore {
match /databases/{database}/documents {
match /places/{document=**} {
allow create, update, delete, read: if true;
}
}
}
在这种情况下,您为所有文档设置规则places
。您也可以在规则模拟器中测试您的规则。这工作得很好。
我希望这能帮到您
推荐阅读
- javascript - 类的 Javascript 语法糖
- r - 在嵌套函数中使用省略号
- python - 我在 conda 环境中安装 Orca 时遇到问题
- powershell - 是否可以链接 Powershell 命令(逻辑链)
- javascript - 如果第一个输入为空,如何使用 jQuery 禁用输入类型日期
- angular - Leaflet - Angular:将大数据矩阵显示为网格的最佳方式
- linux - 查找大小以上的所有文件并截断?
- pandas - 创建 MultiIndex DataFrame 时如何合并公共索引
- apache-camel - 在 SEDA 上启用 bridgeErrorHandler 后,onException(Throwable.class) 未处理异常
- javascript - 在javascript函数中调用java函数