【发布时间】:2019-03-08 01:34:24
【问题描述】:
我正在使用护照通过 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 一起使用。
【问题讨论】:
标签: node.js passport.js passport-facebook