使用身份验证中间件快递资源? [英] Express resources with authentication middleware?
本文介绍了使用身份验证中间件快递资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Passport.js 为node.js和Express提供了非常好的身份验证,包括中间件解决方案:
Passport.js offers great authentication for node.js and Express including a middleware solution:
ensureAuthenticated = function(req, res, next) {
if (req.isAuthenticated()) {
return next();
}
return res.redirect("/login");
};
如何在express-resource模块中使用这个中间件?不幸的是,
How can I use this middleware in the express-resource module? Unfortunately,
app.resource('users', ensureAuthenticated, require('./resources/users'));
无效。
推荐答案
我知道这已经太晚了,原来的帖子已经回复了,但是我正在寻找同样的答案,并找到了一个我认为别人想知道的解决方案。
I know this is a little too late, and the original post was answered, however, I was looking for the same answer and found a solution I thought others might want to know.
只需确保从护照中调用确认。
Just make sure ensureAuthenticated is called from passport.
app.resource('users', passport.ensureAuthenticated, require('./resources/users'));
这里找到: https://gist.github.com/1941301
这篇关于使用身份验证中间件快递资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文