微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在身份验证中以用户身份登录Firebase Google

如何解决在身份验证中以用户身份登录Firebase Google

我正在开发Xamarin.Forms应用。

借助NuGet Plugin.GoogleClient,我已经成功实现了Google登录

问题是,当我想修改Firebase项目规则时,只有经过身份验证的用户才能访问Cloud Firestore数据库。在我的Firebase控制台中,该项目没有任何用户

console1

但是在应用程序中,我可以正常使用我的Google帐户:

enter image description here

我如何验证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.'

但是,如果我将规则设置为true,那么我可以毫无问题地使用我的Google帐户,但是对于异常情况,它没有经过身份验证(?)。

解决方法

要仅允许经过身份验证的用户访问Cloud Firestore中的数据,请查看security rules for all authenticated users上的文档。从那里:

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read,write: if request.auth != null;
    }
  }
}

即使您在Firebase控制台中看不到用户,此操作仍将起作用。只要它们具有Firebase ID令牌,就会在这些安全规则中检查该令牌。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。