我想做的是使用 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>
最佳答案
目前Firebase只支持范围listed here .因此,您不能使用 calendar*
范围通过 Firebase auth 进行身份验证。
此处唯一真正的解决方法是,为避免分别针对 Google 和 Firebase 进行身份验证,使用请求的范围手动针对 Google 进行身份验证,然后将该 OAuth token 传递到 Firebase 的 authWithOAuthToken 中。方法。
换句话说,反转身份验证过程以使用 Google 登录,然后在 Firebase 中重新使用 token 。
关于javascript - Firebase 身份验证和 Google 日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28932427/