根据用户 oauth 电子邮件设置安全规则 firebase
Set a security rule firebase based on a users oauth email
有没有办法安全地获取他们在安全规则中使用 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
.
有没有办法安全地获取他们在安全规则中使用 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
.