gcpug / nouhau

Google Cloud Platformのノウハウを共有するRepository
https://gcpug.jp
MIT License
653 stars 23 forks source link

FirestoreでG Suiteのドメイン指定のセキュリティルールを設定する #57

Open sinmetal opened 6 years ago

sinmetal commented 6 years ago

WHAT

Firebase Auth for Googleを利用してログインし、Firestoreでドメイン指定を行いたい!

WHY

gcpug.jp アカウント限定みたいなことをしたい

sinmetal commented 6 years ago

以下のような感じで、 request.email を見てあげればよいっぽい

service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if false;
    }
    match /users/{userId} {
      allow create,delete,update: if request.auth.uid == userId && request.auth.token.email.matches('.*@gcpug[.]jp');
    }
  }
}
sinmetal commented 6 years ago

カスタムAuthでがんばるという手もある https://github.com/firebase/functions-samples/tree/master/instagram-auth