问题
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