Authenticate Firebase in Polymer using OAuth token

余生颓废 提交于 2019-12-23 05:01:33

问题


I have a Firebase database that authenticates with a Google account. Currently I have a <google-signin-aware> element that details the app's sign-in details for use with the Google Sign-in API, and upon sign-in authenticates a Firebase reference with the access token returned by the Google sign-in.

From the callback for <google-signin-aware> element on successful sign-in:

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){/*...*/});

To try to integrate further with Polymer, I'm migrating to the <firebase-auth> element which is a "wrapper for the Firebase authentication API". However I cannot find an equivalent method to authenticate with an access token. The login() method has two parameters, is there any way to feed the access token to the login method so that Firebase authenticates with this token rather than its own pop-up window?


回答1:


The <firebase-auth> element has an internal Firebase reference ref that you can access by calling

var ref = document.querySelector('#fbauth').ref

And then auth as normal

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



回答2:


You might be interested by my custom set that extends Firebase Polymer element set: https://github.com/MeTaNoV/firebase-element-extended



来源:https://stackoverflow.com/questions/33801186/authenticate-firebase-in-polymer-using-oauth-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!