2015-03-08 115 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) {