9

I'm currently looking to use Firebase for an internal application that can only be accessed by employees with a Google Account from our organization.

I have an understanding how I can restrict read/write access only to google logins, e.g.

{
  "rules": {
    ".read": "auth.provider === 'google'",
    ".write": "auth.provider === 'google'"
  }
}

But I can't figure out how to restrict access to a specific domain/organization within Google accounts. I know this can be done at the application level, but given the number of channels we'd use to access the database, I want to enforce the auth at the database level in addition to the application level.

Has anyone done this before? Thanks.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Will Turnage
  • 113
  • 6

2 Answers2

12

You can restrict access for your gmail domain with:

{
  "rules": {
    ".read": "auth.token.email.endsWith('domain.com')",
    ".write": "auth.token.email.endsWith('domain.com')"
  }
}
halafi
  • 1,064
  • 2
  • 16
  • 26
1

I was also looking for this feature, but it looks like this feature is not available unless you write your own Token/Custom Authentication.

In the future, Firebase states that they "think we have an even better solution." Read more...

Garey
  • 11
  • 3