firebase - Firebase Google 以身份验证中的用户身份登录
问题描述
我正在开发一个 Xamarin.Forms 应用程序。
多亏了 NuGet Plugin.GoogleClient ,我已经成功实现了 Google 登录。
问题是当我想修改 Firebase 项目规则时,只有经过身份验证的用户才能访问 Cloud Firestore 数据库。在我的 Firebase 控制台中,该项目似乎没有任何用户:
但在应用程序中,我使用我的 Google 帐户没有问题:
如何验证 Google 登录帐户,以便它们可以出现在用户中,以便我可以修改 Cloud Firestore 的规则?
编辑:这些是我的 Firebase 规则:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null
}
}
}
在我使用 Google 登录后,我会立即获得Plugin.CloudFirestore.CloudFirestoreException: 'PERMISSION_DENIED: Missing or insufficient permissions.'
.
但是,如果我将规则设置为 just true
,我可以毫无问题地使用我的 Google 帐户,但对于异常状态,它没有经过身份验证 (?)。
解决方案
要仅允许经过身份验证的用户访问 Cloud Firestore 中的数据,请查看有关所有经过身份验证用户的安全规则的文档。从那里:
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
即使您在 Firebase 控制台中看不到用户,这仍然有效。只要他们有 Firebase ID 令牌,就会在这些安全规则中检查该令牌。
推荐阅读
- crystal-reports - 水晶报表运行总计
- ios - 如何使用 dispatch_async
- reactjs - 在现有状态转换错误期间无法更新
- swift - 按下取消按钮时如何防止 UISearchController 关闭?
- ios - 应用因指南 5.2.5 - 法律 - 知识产权而被拒绝
- xamarin.forms - 如何使用 xamarin 表单从条目控件中删除边框
- timezone - 更改 Amazon Lex 聊天机器人时区
- python - 如何验证数组中的值并执行操作 python whatsapp 框架
- kubernetes - helm install istio 返回禁止错误
- c# - 升级到 .NET Core 2.1 后 Http 请求中断