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

后端 未结 6 2023
灰色年华
灰色年华 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:32

    Code which is working for me.

    export class AuthenticationService {
    
        user: Observable;
    
        constructor(public afAuth: AngularFireAuth) {
            this.user = afAuth.authState;
        }
    
        login(){
            var provider = new firebase.auth.GoogleAuthProvider();
            provider.setCustomParameters({'hd': ''});
            this.afAuth.auth.signInWithPopup(provider)
            .then(response => {
                let token = response.credential.accessToken;
                //Your code. Token is now available.
            })
        }
    }
    

提交回复
热议问题