有没有办法安全地获取他们在安全规则中进行 OAuth 验证的电子邮件。
理想情况下,我想创建一个如下规则:
{
".read": "auth.google.email.matches(/@example.com$/)"
".write": "auth.google.email.matches(/@example.com$/)"
}
以便整个应用程序或应用程序的一部分受到电子邮件地址后缀的保护。这是管理我的应用程序的一种更简单的方法,因为用户将根据他们拥有的公司电子邮件获得访问权限,无论全部或全部。
或者有一种方法可以将用户的电子邮件地址保存到数据库中,然后他们就无法写入该数据库,我相信我可以实现类似的过程。
最佳答案
授权。 OAuth 提供程序的属性在安全规则中不可用。根据 documentation on the auth variable :
The predefined
auth
variable is null before authentication takes place. Once a user is authenticated by Firebase Login's auth method, it will contain the following attributes:provider The authentication method used ("password", "anonymous", "facebook", "github", "google", or "twitter").
uid A unique user id, guaranteed to be unique across all providers.
因此,您无法根据电子邮件地址保护数据,除非您使用服务器以安全的方式提供电子邮件域。
一旦您使用服务器,您可以:
- 验证电子邮件地址并将验证的电子邮件地址存储在数据库中。然后,您可以使用
root.child('users').child(auth.uid).child('emailDomain').val()
在安全规则中访问它
- mint your own tokens包含电子邮件域,以便它可以在安全规则的
auth
变量中使用,例如auth.emailDomain
。
关于firebase - 根据用户 oauth 电子邮件设置安全规则 firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35260730/