2015-03-08 65 views
3

我想要做的是使用Firebase与Google进行身份验证。然后从Google日历中获取一些数据。Firebase身份验证和Google日历

我得到了第一部分的工作。我可以通过Google进行身份验证并获取用户名,电子邮件等,但是一旦我将calendar添加到scope,它就会给我401与Error: invalid_scope

它甚至有可能通过Firebase获得这种数据吗?

HTML

<a href="#auth" id="auth">login please</a> 
<a href="#auth" id="calendar">calendar</a> 

JS

<script src="https://cdn.firebase.com/js/client/2.2.2/firebase.js"></script> 
    <script src="js/jquery.js"></script> 
    <script> 
     $("#auth").click(function() { 
     var ref = new Firebase("https://<my-super-cool-app>.firebaseio.com/"); 

     ref.authWithOAuthPopup("google", function(error, authData) { 
      if (error) { 
       console.log("Login Failed!", error); 
       console.log(error); 
      } else { 
       console.log("Authenticated successfully with payload:", authData); 
      } 
     }, { 
      "scope": "email, calendar" 
     }); 

     return false; 
     }); 
     $("#calendar").click(function() { 
     $.getJSON('https://www.googleapis.com/calendar/v3/users/me/calendarList', function(data) { 
      console.log(data); 
     }); 
     }); 
    </script> 
    </body> 
</html> 

回答

2

目前,火力地堡只支持作用域listed here。因此,您不能使用calendar*范围对Firebase身份验证进行身份验证。

为避免单独针对Google和Firebase进行身份验证,唯一真正的解决方法是使用请求的范围对Google进行手动身份验证,然后将该OAuth令牌传递到Firebase的authWithOAuthToken方法中。

换句话说,反转auth过程以使用Google登录,然后在Firebase中重新使用该令牌。

+0

这是多么费事。 :S我希望Firebase只会扩展他们的图书馆以方便访问Google Calendar ... – mesqueeb 2018-02-17 09:00:48

0

我得到了这样的工作。我只是不确定如何使用这些信息,但我有auth部分的工作。希望它能帮助别人。

Auth.$authWithOAuthPopup('google', { 
       remember: "default", 
       scope: 'https://www.googleapis.com/auth/calendar', 
       scope: 'email' 
      }) 
      .then(function (authData) {