我一直在使用passport.js来执行OAuth。因此,身份验证成功后,重定向 URI 就会被命中, 但是对于失败场景。无论如何我都无法触发它,
以下情况会发生什么情况?
<强>1。当 google/twitter 或任何 OAuth 提供商打开其登录页面但用户根本没有响应/关闭浏览器窗口/时,如何在超时后点击失败 URL/重定向 URL。
<强>2。没有任何取消按钮可以中止 Google OAuth 登录,我希望至少会调用失败。
基本上,我想知道的是,所有可能的用例/场景都会调用失败 URL?
Google OAuth 重定向的示例代码,我相信所有 OAuth 提供商的失败场景都是相同的。
app.get('/oauth/failure', function (req, res, next){
console.log('Query params:', req.params.provider);
console.log('failure login called');
res.send("<script> window.close()</script>");
});
app.get('/oauth/redirect/google', passport.authenticate('google', { failureRedirect: '/oauth/failure?provider=google' }), (req, res) => {
if(req.user.id){
// gets executed for successful authentication
let redirectUrl = `http://localhost:8082/auth.html?pid=${req.user.id}`
res.redirect(redirectUrl)
}
});
以上只是 passport-google-oauth
的一个示例,我相信任何 Passport 策略都是如此。
最佳答案
如果身份验证失败(用户输入错误的电子邮件或密码),用户将被重定向回您选择的页面以再次尝试。
关于node.js - Passport.js 失败重定向何时发生?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59526960/