如何使用flutter cloud_firestore软件包传递firestore身份验证令牌 [英] how to pass firestore auth token using flutter cloud_firestore package
问题描述
我正在使用 firebase auth REST api 进行身份验证;这部分工作正常,因为我可以登录/注册用户,并且可以返回uid
和auth token
.
I am using firebase auth REST api to do authentication; this part works fine as I can log in/sign up users and I can get a uid
and auth token
back.
尝试写入Cloud Firestore时,如果我将Cloud Firestore数据库规则设置为(这是最基本的身份验证规则之一):
When trying to write to cloud firestore, if I set my Cloud Firestore database rule to (which is one of the most basic auth rules):
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
}
}
但是如何使用cloud_firestore
包将uid
传递到云存储请求我想写一个收藏集:
But how to pass in the uid
to the a cloud firestore request using cloud_firestore
package e.g. I want to write to a collection:
Firestore.instance.collection('myCollection').document() .setData(myData);
推荐答案
以防万一这对其他人有帮助,我被告知我不应该将Firebase auth REST api与firestore non-REST api混合使用. 如果我想使用cloud_firestore软件包,我也将使用firebase_auth软件包,以便firebase_auth将采用基础身份验证的情况,而无需cloud_firestore显式传递任何身份验证令牌.
Just in case this helps someone else, I was told that I shouldn't mix firebase auth REST api with firestore non-REST api. If I want to use cloud_firestore package, I shall use firebase_auth package too so that firebase_auth will take case of the underlying authentication without requiring cloud_firestore to pass any auth token explicitly.
同时,firestore确实也具有 REST API ;因此,如果某人真的想使用firebase auth REST api,则还应该使用firestore REST api,以便可以显式传递auth令牌.
In the meantime, firestore does have a REST api too; so if someone really wants to use firebase auth REST api, then firestore REST api should also be used so that an auth token can be passed explicitly.
这篇关于如何使用flutter cloud_firestore软件包传递firestore身份验证令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!