使用Google Signin和Firebase身份验证需要两次登录?

时间:2015-12-29 23:19:47

标签: authentication google-api firebase firebase-authentication google-api-js-client

我可能会遇到一些令人困惑的问题:

我在我的应用Firebase中使用来存储用户数据等并保护用户的数据我使用Google Authentication中的版本。我认识到我可以在此signIn流程中定义scopes,用户可以/应该允许,但我注意到您无法提出所有Google范围/服务,(所有这些都包含{{ 1}}内置功能)

因此我必须使用Firebase进行身份验证,以访问存储在Google JS Library上的其余用户数据(我想在我的Web应用程序中显示用户)。

如果Google显示两次,一次授权为Google signin popup,另一次授权为Firebase,则可能会有点混乱。

我的问题是,有没有办法可以移交Google API's access_token(反之亦然),我不会让用户签署两次Firebase signin process仅显示一次

1 个答案:

答案 0 :(得分:1)

您可以使用从Google身份验证中获得的令牌致电authWithOAuthToken:请参阅https://www.firebase.com/docs/web/api/firebase/authwithoauthtoken.html。从那里:

  

此方法接受OAuth凭据的单个字符串参数(例如OAuth 2.0承载访问令牌)或对象(例如一组OAuth 1.0a凭证)。使用OAuth令牌登录Facebook,GitHub和Google只需要一个字符串访问令牌:

// Authenticate with Facebook using an existing OAuth 2.0 access token
var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com");
ref.authWithOAuthToken("facebook", "<ACCESS-TOKEN>", function(error, authData) {
  if (error) {
    console.log("Login Failed!", error);
  } else {
    console.log("Authenticated successfully with payload:", authData);
  }
});

来自文档的示例使用Facebook,但这同样适用于Google令牌。