我正在尝试构建一个与Google云端硬盘集成并安装到其中的网络应用.用户将能够在其驱动器中创建和共享我的应用程序文件.我正在尝试使用Firebase编写它,以便我可以利用那里的许多出色的新功能.但是,我无法让auth在这两个平台上一致地工作.
这是一个仅限客户端的应用程序(至少目前为止),因此我无法使用脱机身份验证和刷新令牌.
在Firebase身份验证之前,我会使用带有gapi的Google Identity Toolkit.这通常工作正常,虽然它使用不适合移动设备的弹出流程.
gapi.signin2.render(elementId, {
longtitle: true,
width: 230,
height: 50,
theme: "dark"
});
var auth2 = gapi.auth2.init({
client_id: CLIENT_ID,
scope: SCOPES.join(" ")
});
auth2.isSignedIn.listen(signinChanged);
auth2.currentUser.listen(userChanged);
Run Code Online (Sandbox Code Playgroud)
Gapi有点笨拙,但它确实有效.该访问令牌可以通过调用来获得
gapi.auth2.getAuthInstance().currentUser.get().getAuthResponse(true));
Run Code Online (Sandbox Code Playgroud)
像往常一样,访问令牌只持续大约一个小时然后到期.在重要的事情是,我们只需调用GoogleUser.reloadAuthResponse()得到刷新访问令牌.注意,这是刷新的访问令牌,而不是刷新令牌!
因此,从理论上讲,我可以使用该访问令牌来对Firebase进行身份验证,如此处所述,并且必须使用弹出流程,或者试图破解它.
尽管如此,Google表示Identity Toolkit正在被Firebase身份验证取代,新应用程序应该使用Firebase.
最新版本的Google Identity Toolkit已作为Firebase身份验证发布.它包括升级的客户端SDK,开源UI库,会话管理和用于忘记密码流的集成电子邮件发送服务.
新项目应使用Firebase身份验证.要将现有项目从Identity Toolkit迁移到Firebase身份验证,请参阅迁移指南.
Firebase有一个简单的API用于与Google进行身份验证.我可以在验证时获取并存储AccessToken.所以这似乎是我应该实现auth的方式,新的和改进的Firebase方式.此外,Firebase提供了一个很好的重定向流程,适用于移动设备.
但是,存在一个巨大的问题......
这将获得访问令牌.
firebase.auth().getRedirectResult().then(function(result) {
if (result.credential) {
// This gives you a Google Access Token. You can use it to access the Google API.
var …Run Code Online (Sandbox Code Playgroud) google-authentication firebase google-drive-api google-identity-toolkit firebase-authentication
我正在使用AngularJS,Firebase(SDK v3)和Google Calendar API构建Web应用程序.我正在使用Google OAuth对用户进行身份验证.我的目的是能够从Firebase中的数据库节点创建日历事件.到目前为止,我已设法请求访问日历范围:
_authProvider = new firebase.auth.GoogleAuthProvider();
// Get permission to manage Calendar
_authProvider.addScope("https://www.googleapis.com/auth/calendar");
_fbAuthObject.signInWithRedirect(_authProvider);
Run Code Online (Sandbox Code Playgroud)
我正在使用重定向流进行身份验证,因此身份验证重定向可用:
_fbAuthObject.getRedirectResult()
.then(function _readToken(result) {
if (result.credential) {
_googleToken = result.credential.accessToken;
var authHeader = 'Bearer '+ _googleToken;
// Just a test call to the api, returns 200 OK
$http({
method: 'GET',
headers: {
'Authorization': authHeader
},
url: 'https://www.googleapis.com/calendar/v3/users/me/calendarList/primary'
})
.then(function success(response) {
console.log('Cal response', response);
},
function error(response) {
console.log('Error', response);
});
Run Code Online (Sandbox Code Playgroud)
但是,在初始登录之外,似乎无法通过Firebase SDK获取Google访问令牌.似乎只能访问Firebase JWT令牌,而不能使用Calendar API.我可以存储访问令牌,但这不能解决刷新令牌等问题.有没有办法通过Firebase SDK获取当前的Google Access令牌,如果没有,那么有什么其他解决方案可以解决问题两次验证用户?
更新1:
好像其他人一直在努力解决与Facebook身份验证相似的问题.在该问题上,有一个指向Firebase文档 …
authentication google-calendar-api angularjs firebase firebase-authentication