passport本地策略与自定义代码的对比
// passport involved code
app.post('/login',
passport.authenticate('local'),
function(req, res) {
// If this function gets called, authentication was successful.
// `req.user` contains the authenticated user.
res.redirect('/users/' + req.user.username);
});我还可以调用本地函数,它可以检查与passport本地策略检查相同的内容,因此为什么要创建本地策略
// custom checking function
app.post('/login',
customfunctionhere,
function(req, res) {
// If this function gets called, authentication was successful.
// `req.user` contains the authenticated user.
res.redirect('/users/' + req.user.username);
});发布于 2016-06-28 00:26:28
可以,您可以编写自己的本地策略函数。然而,passport为您提供了额外的功能,如持久化登录(Cookie)、轻松处理成功和失败等等。
另外,如果您使用其他策略,如OAuth或google/fb/twitter单点登录,那么使用passport进行所有身份验证都是有意义的。
注意:您不会将验证函数传递给passport.authenticate()。有关更多信息,请查看passport-local文档:https://github.com/jaredhanson/passport-local
https://stackoverflow.com/questions/38058483
复制相似问题