dim*_*zen 1 redirect oauth infinite firebase
我是Firebase的新手.我正在尝试将Google OAuth连接到我的Firebase实例.
我设置了一切,并获得客户端ID和客户端分泌.我将localhost添加到Firebase信息中心的白名单中.然后我使用了下面的Firebase示例:
<html>
<head>
<script src="https://cdn.firebase.com/js/client/2.0.4/firebase.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
</head>
<body>
<script>
var ref = new Firebase("https://<firebase url>.firebaseio.com");
ref.authWithOAuthRedirect("google", function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
}
});
</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我打开它时,它会要求允许通过Google进行身份验证.当我接受它时,它只是继续进行重定向(无限)并且没有完成加载.对问题的任何见解都会有所帮助.谢谢.
编辑:我注意到:authWithOAuthPopup()方法有效但重定向只是停留在无限重定向循环中.
您ref.authWithOAuthRedirect(...)每次拨打电话时都会告诉Firebase启动基于重定向的身份验证流程,并将浏览器重定向到OAuth提供商.调用此方法将始终尝试创建新会话,即使已在浏览器中保留了该会话.
要仅尝试创建新的登录会话(如果尚不存在),请尝试使用以下onAuth(...)事件监听器:
var ref = new Firebase("https://<firebase url>.firebaseio.com");
ref.onAuth(function(authData) {
if (authData !== null) {
console.log("Authenticated successfully with payload:", authData);
} else {
// Try to authenticate with Google via OAuth redirection
ref.authWithOAuthRedirect("google", function(error, authData) {
if (error) {
console.log("Login Failed!", error);
}
});
}
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1775 次 |
| 最近记录: |