Firebase身份验证和Google日历 [英] Firebase Auth and Google Calendar

查看:166
本文介绍了Firebase身份验证和Google日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我得到了第一部分的工作。我可以通过Google进行身份验证并获取用户名,电子邮件等信息,但是一旦将 calendar 添加到范围中,我401与错误:invalid_scope



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

 < a href = #authid =auth>请登入< / a> 
< a href =#authid =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 successful with payload:,authData);
}
},{
范围:电子邮件,日历
});

返回false;
});点击(功能(){
$ .getJSON('https://www.googleapis.com/calendar/v3/users/me/calendarList',功能($数据){
console.log(data);
});
});
< / script>
< / body>
< / html>


解决方案

目前,Firebase只支持范围列在这里。因此,您不能使用日历* 作用域进行Firebase身份验证。

,为了避免单独针对Google和Firebase进行身份验证,应该使用请求的范围对Google进行手动身份验证,然后将该OAuth令牌传递到Firebase的 authWithOAuthToken 方法。换句话说,反转auth过程以使用Google登录,然后在Firebase中重新使用该标记。

What I am trying to do is use Firebase to authenticate with Google. Then get some data from Google Calendar.

I got the first part working. I can authenticate with Google and get user name, email ect., but once I add calendar to the scope it gives me 401 with Error: invalid_scope.

Is it even possible to get that kind of data with 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>

解决方案

At present, Firebase only supports scopes listed here. Thus, you can't use the calendar* scopes to authenticate with Firebase auth.

The only real workaround here, to avoid authenticating separately against Google and Firebase, would be to manually authenticate against Google with the requested scopes, then pass that OAuth token into Firebase's authWithOAuthToken method.

In other words, reverse the auth process to log in with Google and then re-use the token in Firebase.

这篇关于Firebase身份验证和Google日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆