我正试图使用Xamarin for Visual Studio中制作的跨平台应用程序访问我的firebase项目。我使用Plugin.CloudFirestore
NuGet包访问数据库,使用FirebaseAuthentication.net
NuGet包处理身份验证。我能够注册和登录用户,这是正常的工作。当规则打开时,我可以访问Cloud Firestore数据库:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true;
}
}
}
然而,当我尝试使用谷歌提供的规则来检查经过身份验证的用户时:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth != null;
}
}
}
我得到了错误:
插件.CloudFirestore.CloudFirestore异常:'PERMISSION_DENIED:缺少或权限不足。'
我相信这是因为我的请求中没有发送身份验证令牌,但我似乎不知道如何使用Plugin.CloudFirestore
发送此令牌。
根据Cherry Bu:
您可能需要使用FirebaseAuth.Instance.SignInWithCredentialAsync
来传递电子邮件和密码作为参数,并调用一个方法来验证用户,然后我们返回一个令牌。我发现了一条类似的线索,你可以看看。