【发布时间】:2015-01-09 06:11:44
【问题描述】:
我遇到了一个问题,尽管登录成功(如successRedirect 处理程序触发所证明),请求仍未通过身份验证,因此我的身份验证中间件再次将我们发送回登录页面。
我的路线如下:
// ROUTES
module.exports = function(app, passport) {
app.get('/home', isLoggedIn, function(req, res) {
res.sendfile('imconfusedindex.html'); // this never gets sent.
});
app.post('/login', passport.authenticate('ldap-auth', {
successRedirect: '/home',
failureRedirect: '/login'
}));
}
// route middleware to make sure a user is logged in
function isLoggedIn(req, res, next) {
// if user is authenticated, we'll all float on OK
if (req.isAuthenticated()) {
return next();
}
// otherwise, redirect them to the login page
res.redirect('/login');
}
我的护照配置如下:
passport.serializeUser(function(user, done) {
done(null, user.user_id);
});
passport.deserializeUser(function(id, done) {
connection.query("select * from users where user_id = " + id, function(err, rows) {
done(err, rows[0]);
});
});
passport.use('ldap-auth', new LocalStrategy(
function(username, password, done) {
done(null, {user_id: 2, username: 'bob'});
})
);
正如您在护照配置中看到的那样,我每次都返回一个虚拟用户。再做调试,发现请求正在被认证,但是重定向之后,就不再认证了。
不确定该怎么做,任何想法都将不胜感激。
【问题讨论】:
标签: node.js express passport.js