How do I lock down Firebase Database to any user from a specific (email) domain?

后端 未结 6 2041
灰色年华
灰色年华 2020-11-22 08:36

I have a small, personal Firebase webapp that uses Firebase Database. I want to secure (lock down) this app to any user from a single, specific domain. I want to authenticat

6条回答
  •  生来不讨喜
    2020-11-22 09:34

    If you're using the new Firebase this is now possible, since the email is available in the security rules.

    In the security rules you can access both the email address and whether it is verified, which makes some great use-cases possible. With these rules for example only an authenticated, verified gmail user can write their profile:

    {
      "rules": {
        ".read": "auth != null",
        "gmailUsers": {
          "$uid": {
            ".write": "auth.token.email_verified == true && 
                       auth.token.email.matches(/.*@gmail.com$/)"
          }
        }
      }
    }
    

    You can enter these rules in the Firebase Database console of your project.

提交回复
热议问题