Firebase身份验证和Google日历 [英] Firebase Auth and Google Calendar
问题描述
我得到了第一部分的工作。我可以通过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身份验证。
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屋!