node.js - Facebook 失败时 Passport 不会重定向到 'failureRedirect'

标签 node.js passport.js passport-facebook

我正在使用 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/

相关文章:

node.js - NodeJS Passport - Facebook 身份验证

Node.js google drive api - 未经同意屏幕授权

javascript - 快速 session 不适用于 firebase 功能

https - 不安全登录被阻止 : You can't get an access token or log in to this app from an insecure page. 尝试将页面重新加载为 https://

node.js - 将 Passport 使用从 Mongoose 转换为 Sequelize

node.js - Passport.js:passport-facebook-token 策略,通过 JS SDK 登录然后验证 Passport ?

javascript - Passport-Facebook 身份验证窗口未弹出,用户仍添加

node.js - 在 root 模式下设置 Node-red 密码

c# 打开cmd并继续-nodeJS仪表板更新

node.js - 使用 Electron 在触摸条 slider 上显示值