(updated code with serialization functions - still redirecting to / failedRedirect)
I am trying to get a simple authentication of a username and password using a passport package, but it fails. In the example below, I tried to verify that authentication works, basically always returning valid authentication (no matter what is being transmitted), but for some reason it fails and the passport redirects to the failed login link.
If anyone can help me figure out how to get this example, just to authenticate something, I should be able to manage from there.
Code in coffeescript file:
express = require "express" passport = require "passport" LocalStrategy = require("passport-local").Strategy passport.use(new LocalStrategy( (username, password, done) -> console.log "LocalStrategy invoked" done(null, {id: 1, name: "Marius"}) )) passport.serializeUser (user, done) -> done null, user passport.deserializeUser (obj, done) -> done null, obj app = express.createServer() app.configure -> app.use express.bodyParser() app.use express.static("./public") app.use express.cookieParser("SOMESECRET") app.use express.session secret: "SOMESECRET" cookie: maxAge: 60000 app.use passport.initialize() app.use passport.session() app.set "view", "./srv/views" app.set "view engine", "jade" app.get "/login", (req, res) -> res.send "login page" app.post "/login", passport.authenticate("local", failureRedirect: "/failedRedirect" successRedirect: "/successRedirect" failureFlash: true) app.listen 8082
Solved: Well, I believe that there were several reasons why I could not get it to work. Serialized material may be one (I have not tested), but since Jared says they are needed, I leave them (he is the author of the Passport). Another confusion could be related to express versions and my confusion with npm. I believe that I tested as the latest version of v2, but I also tested v3, which I am launching now. For the third version, you should probably check the connect-flash module on Github, and some of the "flash files" used in the Jared examples have been ported from express v3 (so the module returns it back ...). Finally, make sure that you use the appropriate input name names ( username and password ) by default.
Marius kjeldahl
source share