我用我的网站创建了一个谷歌联合登录。它充当身份验证层,因此我只有我所针对的精选用户群。当用户登录时,我如何以及从用户那里获取哪些信息?
至于您获得的有关用户的信息,您可以查看可用属性的列表以及您将在官方文档中检索的信息。
但是对于您关于如何将"选定人群"列入白名单的问题:您可以做的是创建数据库安全规则,这些规则正在检查身份验证对象并根据其电子邮件地址限制访问。
实时数据库
{
"rules": {
".read": "(auth.token.email == 'mybuddy@gmail.com' || auth.token.email == 'anotherfriend@gmail.com')",
".write": "(auth.token.email == 'mybuddy@gmail.com' || auth.token.email == 'anotherfriend@gmail.com')"
}
}
菲利姆
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if isWhiteListedUser();
}
}
function isWhiteListedUser () {
return request.auth.token.email == 'mybuddy@gmail.com'
|| request.auth.token.email == 'anotherfriend@gmail.com';
}
}
将整个用户域列入白名单
如果您的 Google 登录应仅限于 Gsuite 帐户的某个域,您也可以检查其电子邮件地址是否以您希望允许使用您的应用的域结尾。
".read": "auth.token.identifier.endsWith('@company.com')"
确定的最简单方法?使用浏览器开发工具(cntrl + shift + i)浏览用户对象。
在你的.onAuthStateChanged
观察者里面放console.dir(firebase.auth().currentUser)
.
登录,然后检查开发工具控制台。现在,您将拥有一个可扩展的 Firebase 用户对象,其中包含 Firebase 为您提供的有关该用户的任何内容。