Firebase Google sign-in as Users in Authentication

有些话、适合烂在心里 提交于 2021-01-29 14:01:25

问题


I'm developing a Xamarin.Forms app.

I've succesfully implemented Google sign-in thanks to the NuGet 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 (?).


回答1:


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.



来源:https://stackoverflow.com/questions/63641939/firebase-google-sign-in-as-users-in-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!