Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can Firebase + Google OAuth be configured with a specific "hd" (hosted domain) parameter?

I'm using Firebase with the Google authentication provider.

When using Google OAuth in other applications, I'm able configure authentication to be restricted to specific domains.

The Google OpenID Connect documentation details the "hd" parameter which is used for this functionality. https://developers.google.com/identity/protocols/OpenIDConnect#hd-param

How can this be configured for Firebase?

like image 979
Daniel Armando Martinez Avatar asked Jan 09 '16 04:01

Daniel Armando Martinez


People also ask

How do I use Google authentication with Firebase?

In the Firebase console, open the Auth section. On the Sign in method tab, enable the Google sign-in method and click Save.

Does Firebase Auth use OAuth?

Firebase Authentication integrates tightly with other Firebase services, and it leverages industry standards like OAuth 2.0 and OpenID Connect, so it can be easily integrated with your custom backend.


1 Answers

With the new setCustomParameters function, you can add the hd parameter

var provider = new firebase.auth.GoogleAuthProvider();
provider.addScope('email');
provider.setCustomParameters({
    'hd': 'uw.edu'
});
firebase.auth().signInWithRedirect(provider);

Here is the API Doc https://firebase.google.com/docs/reference/js/firebase.auth.GoogleAuthProvider#setCustomParameters

Requires at least Firebase Version 3.5.0 - October 14, 2016. https://firebase.google.com/support/release-notes/js

like image 138
Alexander Bell-Towne Avatar answered Nov 01 '22 17:11

Alexander Bell-Towne