【发布时间】:2017-02-16 07:33:13
【问题描述】:
我正在使用 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);
我正在使用重定向流进行身份验证,因此身份验证重定向可用作:
_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);
});
但是,在初始登录之外,似乎无法通过 Firebase SDK 获取 Google 访问令牌。似乎只能访问 Firebase JWT 令牌,而不能使用 Calendar API。我可以存储访问令牌,但这在刷新令牌等时无法解决问题。有没有办法使用 Firebase SDK 获取当前的 Google 访问令牌,如果没有,还有什么其他解决方案可以解决这个问题对用户进行两次身份验证?
更新 1:
好像someone else has struggled with similar problems with Facebook authentication。关于那个问题,有一个 link to the Firebase documentation 声明 Firebase 身份验证不再保留访问令牌。那么如何处理令牌刷新?真的没有答案吗?
更新 2:
因此,我联系了 Firebase 支持并提出了有关此问题的功能请求,他们给了我以下答案:
感谢您抽出宝贵时间给我们写信。
我明白了你的意思,这确实是一个很好的建议。我们清楚地知道,许多用户,例如您自己,都希望在刷新时访问令牌的 OAuth 功能。我们正在探索潜在的解决方案,但我不能保证这是否会很快推出。不过,我们会继续考虑您的反馈意见。持续改进对我们的社区非常重要,因此感谢您提出这个问题!
请留意我们的发行说明以获取任何进一步的更新。
因此,目前似乎无法通过 Firebase SDK 获得访问令牌。我仍在努力寻找解决方法,所以如果有人对有效的解决方案有想法,我会很高兴听到他们的声音。当然,如果我自己找到可行的解决方案,我会在这里发布。
【问题讨论】:
-
我认为应该将细节添加到 currentUser 对象中,您是否尝试过检查当前用户对象中存在的内容?
firebase.auth().currentUser;firebase.google.com/docs/auth/web/manage-users -
是的,但我似乎无法从那里找到 Google 令牌。我也尝试过 getToken() 函数,但 Firebase JWT 令牌不能与 Google API 一起使用。
标签: angularjs authentication firebase google-calendar-api firebase-authentication