小编Ron*_*iPa的帖子

使用Firebase Auth访问Google Calendar API

我正在使用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

9
推荐指数
1
解决办法
4158
查看次数