在身份验证中以用户身份登录Google Firebase [英] Firebase Google sign-in as Users in Authentication

查看:60
本文介绍了在身份验证中以用户身份登录Google Firebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Xamarin.Forms应用.

借助NuGet

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

我如何验证Google登录帐户,以便它们可以出现在用户"中,从而可以修改Cloud Firestore的规则?

这是我的Firebase规则:

  rules_version ='2';服务cloud.firestore {匹配/databases/{database}/documents {匹配/{document = **} {允许读写:if request.auth!= null}}} 

使用Google登录后,我立即得到 Plugin.CloudFirestore.CloudFirestoreException:'PERMISSION_DENIED:缺少权限或权限不足.'.

但是,如果我将规则设置为 true ,则我可以毫无问题地使用我的Google帐户,但是对于异常所指出的内容,它不会进行身份验证(?).

解决方案

要仅允许经过身份验证的用户访问Cloud Firestore中的数据,请查看Plugin.GoogleClient.

The problem is when I want to modify the Firebase project rules so only authenticated users can access to the Cloud Firestore database. In my Firebase console appears that the project doesn't have any user:

But in the app I'm using my Google account with no problem:

How can I authenticate Google signed-in accounts so they can appear in Users, so I can modify the rules of the Cloud Firestore?

Edit: these are my Firebase rules:

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

Immediately after I sign in with Google, I get Plugin.CloudFirestore.CloudFirestoreException: 'PERMISSION_DENIED: Missing or insufficient permissions.'.

However, if I set the rules to be just true, I can use my Google account with no problems, but for what the exception states, it isn't authenticated (?).

解决方案

To allow only authenticated users access to the data in Cloud Firestore, have a look at the documentation on security rules for all authenticated users. From there:

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

This will still work even when you don't see the user in the Firebase console. As long as they have a Firebase ID token, that token will be checked in these security rules.

这篇关于在身份验证中以用户身份登录Google Firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆