我正在使用 Passport 通过 Facebook 对用户进行身份验证。
successRedirect
效果很好 [我正在重定向到 http://localhost:3000/success#_=_
],但是 failureRedirect
没有,我得到这个:
FacebookAuthorizationError: Login Error: There is an error in logging you into this application. Please try again later.
[I'm getting this in my browser-> http://localhost:3000/auth/facebook/callback?error_code=1349003&error_message=Login+Error%3A+There+is+an+error+in+logging+you+into+this+application.+Please+try+again+later.#_=_
这些是我的设置:
app.use(passport.initialize());
app.use(passport.session());
passport.serializeUser(function (user, done) {
console.log(user);
done(null, 'this is the user');
})
passport.deserializeUser(function (id, done) {
console.log(id);
done(err, {message: 'this is the user'});
});
router.get('/auth/facebook', passport.authenticate('facebook'));
router.get(
'/auth/facebook/callback',
passport.authenticate('facebook',
{
successRedirect: '/success',
failureRedirect: '/login',
}
),
);
const FacebookStrategy = require('passport-facebook').Strategy;
const facebookStrategy = new FacebookStrategy({
clientID: staretegy.clientId,
clientSecret: staretegy.clientSecret,
callbackURL: staretegy.callbackURL,
profileFields: [
'id',
'first_name',
'middle_name',
'last_name',
],
}, (accessToken, refreshToken, profile, done) => {
done(null, {user: profile});
});
passport.use(facebookStrategy);
当我在文档中阅读时,我希望重定向到 /login。
/login
可以通过浏览器访问。 (我也尝试过输入完整的 URL 路径:failureRedirect: http://localhost:3000/login
但它不起作用,类似的 URL 可与 successRedirect
一起使用>.
最佳答案
这似乎是 open issue并且主存储库几乎不支持。但你可以尝试使用this fork .
关于node.js - Facebook 失败时 Passport 不会重定向到 'failureRedirect',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52616560/