如何使用特定的“hd”(托管域)参数配置Firebase + Google OAuth?

时间:2016-01-09 04:37:52

标签: firebase firebase-authentication

我正在将Firebase与Google身份验证提供程序一起使用。

在其他应用程序中使用Google OAuth时,我可以将身份验证配置为仅限于特定域。

Google OpenID Connect文档详细说明了用于此功能的“hd”参数。 https://developers.google.com/identity/protocols/OpenIDConnect#hd-param

如何为Firebase配置?

1 个答案:

答案 0 :(得分:0)

使用新的setCustomParameters函数,您可以添加hd参数

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

以下是API文档https://firebase.google.com/docs/reference/js/firebase.auth.GoogleAuthProvider#setCustomParameters

至少需要Firebase版本3.5.0 - 2016年10月14日。https://firebase.google.com/support/release-notes/js