Firebase Auth和Google日历

Teo*_*ors 5 javascript firebase

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

我得到了第一部分工作.我可以通过Google验证并获取用户名,电子邮件等,但是一旦我添加calendarscope它就会给我401 Error: invalid_scope.

是否有可能使用Firebase获取此类数据?

HTML

<a href="#auth" id="auth">login please</a>
<a href="#auth" id="calendar">calendar</a>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

Kat*_*ato 3

目前,Firebase 仅支持此处列出的范围。因此,您无法使用calendar*范围通过 Firebase 身份验证进行身份验证。

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

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