firebase - 根据用户 oauth 电子邮件设置安全规则 firebase

标签 firebase firebase-security

有没有办法安全地获取他们在安全规则中进行 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/

相关文章:

javascript - Firebase .push() 抛出 'permission_denied' 错误

android - Firebase 实时数据库 - 自动生成主键

ios - 升级到 FirebaseCrashlytics 和 'No such module FirebaseCrashlytics'

java - Android App 在 firebase 发布数据到服务器时崩溃

带有 Firestore : delete specific fields from a document 的 Angularfire2

android - 允许更新特定用户的特定字段 - Firebase Firestore 规则

firebase - Firebase 实时数据库安全规则中的 auth.uid 和 auth.token.sub 有什么区别

firebase - Firestore 规则 - 数据类型验证

android - 如何删除 "expired"或 Android Studio 上当前日期之后的 firebase 项目?

Firebase 安全规则限制字符串中的某些字符