Node.js passport skips strategy
Problem
This coffee-script passport implementation looks just like the examples to me but fails every time and never prints "Trying out the strategy". I just get redirected to "/fail". I tried naming the Strategy as well as executing it in the (req, res, next) handler. I also verified that the form posted sent the username and password in those fields and tried renaming them with a mapping in the strategy according to the examples to no avail. Any tips on what I'm overlooking?
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
Solution Modify express configuration:
app.configure () ->
app.use exp.bodyParser()
Solution
Turns out this problem was due to my ignorance of express. I was sending the username and password but wasn't parsing it - app.configure requires express.bodyParser() in order to utilize the strategies.
Discussion
View additional discussion.