这个咖啡脚本护照实现看起来就像我的例子,但每次都失败并且从不打印“尝试策略”。我只是被重定向到“/失败”。我尝试命名策略并在 (req, res, next) 处理程序中执行它。我还验证了发布的表单在这些字段中发送了用户名和密码,并尝试根据示例使用策略中的映射重命名它们,但无济于事。关于我忽略的任何提示?
pass = require 'passport'
strat = require('passport-local').Strategy
exp = require 'express'
app = exp.createServer()
# Configure strategy
pass.use new strat (username, password, done) ->
#Logic to find user
console.log("Trying out the strategy")
user = {nm:username,ps:password}
done(null,user)
app.configure () ->
app.use (req,res,next) ->
console.log("GOT A REQ")
next()
app.use pass.initialize()
ops = { failureRedirect: '/fail' }
app.post '/auth', pass.authenticate('local',ops), (req, res, next) ->
console.log "what about here"
app.listen 1337
解决 方法 修改 express 配置:
app.configure () ->
app.use exp.bodyParser()