使用 OAuth 令牌在 Polymer 中验证 Firebase

Authenticate Firebase in Polymer using OAuth token

我有一个使用 Google 帐户进行身份验证的 Firebase 数据库。目前我有一个 <google-signin-aware> 元素,它详细说明了用于 Google 登录 API 的应用程序登录详细信息,并且在登录时使用返回的访问令牌对 Firebase 引用进行身份验证通过 Google 登录。

来自成功登录时 <google-signin-aware> 元素的回调:

var ref = new Firebase("https://<myapp>.firebaseio.com");
var access_token = gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse().access_token;
ref.authWithOAuthToken("google", access_token, function (error, authData){/*...*/});

为了尝试与 Polymer 进一步集成,我正在迁移到 <firebase-auth> 元素,它是 "wrapper for the Firebase authentication API"。但是我找不到等效的方法来使用访问令牌进行身份验证。 login() 方法有两个参数,有没有办法将访问令牌提供给登录方法,以便 Firebase 使用此令牌而不是其自己的弹出窗口进行身份验证 window?

<firebase-auth> 元素有一个内部 Firebase 引用 ref,您可以通过调用

来访问它
var ref = document.querySelector('#fbauth').ref

然后正常认证

var access_token = gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse().access_token;
ref.authWithOAuthToken("google", access_token, function (error, authData){/*...*/});

您可能对我扩展 Firebase Polymer 元素集的自定义集感兴趣:https://github.com/MeTaNoV/firebase-element-extended