passport-local

Sending back a JSON response when failing Passport.js authentication

我的梦境 提交于 2019-11-29 20:24:20
I'm using Node.js as a backend API server for an iPhone client. I'm using Passport.js to authenticate with a local strategy . The relevant code is below: // This is in user.js, my user model UserSchema.static('authenticate', function(username, password, callback) { this.findOne({ username: username }, function(err, user) { if (err){ console.log('findOne error occurred'); return callback(err); } if (!user){ return callback(null, false); } user.verifyPassword(password, function(err, passwordCorrect){ if (err){ console.log('verifyPassword error occurred'); return callback(err); } if (

Passport js local strategy custom callback showing user as false and info as “Missing credentials”

感情迁移 提交于 2019-11-29 17:23:47
I am using Node.js,angularjs,express and passport. I have tried all options I can think of, but still no solution. Couldn't find a solution from other posts for this problem. app.post('/login', function(req, res, next) { console.log(req.body.Email); console.log(req.body.Password); passport.authenticate('local', function(err, user, info) { console.log(err,user,info); ... In above req.body is showing correct in console but in passport authenticate it is showing null,false and info as missing credentials. I have used the following for pass port passport.use(new LocalStrategy({ usernameField:

How does passport js stores user object in session?

孤街醉人 提交于 2019-11-28 19:25:08
I am using node/express with passport in my development. I came across an article which says: Express loads the session data and attaches it to the req. As passport stores the serialised user in the session, the serialised user object can be found at req.session.passport.user. But to my surprise, the value for sessionID stores in the browser cookies remain the same before and after login. So where does the serialised user object is stored? I thought that it was stored in the user sessionid cookie initially but it seems that this is not the case as I still can access my user object with req

Sending back a JSON response when failing Passport.js authentication

我的未来我决定 提交于 2019-11-28 16:16:33
问题 I'm using Node.js as a backend API server for an iPhone client. I'm using Passport.js to authenticate with a local strategy . The relevant code is below: // This is in user.js, my user model UserSchema.static('authenticate', function(username, password, callback) { this.findOne({ username: username }, function(err, user) { if (err){ console.log('findOne error occurred'); return callback(err); } if (!user){ return callback(null, false); } user.verifyPassword(password, function(err,

Passport js local strategy custom callback showing user as false and info as “Missing credentials”

故事扮演 提交于 2019-11-28 11:50:49
问题 I am using Node.js,angularjs,express and passport. I have tried all options I can think of, but still no solution. Couldn't find a solution from other posts for this problem. app.post('/login', function(req, res, next) { console.log(req.body.Email); console.log(req.body.Password); passport.authenticate('local', function(err, user, info) { console.log(err,user,info); ... In above req.body is showing correct in console but in passport authenticate it is showing null,false and info as missing

Can you authenticate with Passport without redirecting?

廉价感情. 提交于 2019-11-27 14:51:52
问题 I have the following working code to authenticate through the passport-local strategy: app.post('/api/login', passport.authenticate('local-login', { successRedirect : '/api/login/success', failureRedirect : '/api/login/error', failureFlash : true })); app.get('/api/login/error', function(req, res) { res.send(401, {error: req.flash('loginMessage')}); }); app.get('/api/login/success', function(req, res) { res.send(200, {user: req.user}); }); However, ideally I want to handle the errors and

How does passport js stores user object in session?

会有一股神秘感。 提交于 2019-11-27 12:18:27
问题 I am using node/express with passport in my development. I came across an article which says: Express loads the session data and attaches it to the req. As passport stores the serialised user in the session, the serialised user object can be found at req.session.passport.user. But to my surprise, the value for sessionID stores in the browser cookies remain the same before and after login. So where does the serialised user object is stored? I thought that it was stored in the user sessionid

passport's req.isAuthenticated always returning false, even when I hardcode done(null, true)

和自甴很熟 提交于 2019-11-27 07:34:06
I'm trying to get my Passport local strategy working. I've got this middleware set up: passport.use(new LocalStrategy(function(username, password, done) { //return done(null, user); if (username=='ben' && password=='benny'){ console.log("Password correct"); return done(null, true); } else return done(null, false, {message: "Incorrect Login"}); })); but then in here app.use('/admin', adminIsLoggedIn, admin); function adminIsLoggedIn(req, res, next) { // if user is authenticated in the session, carry on if (req.isAuthenticated()) return next(); // if they aren't redirect them to the home page

passport's req.isAuthenticated always returning false, even when I hardcode done(null, true)

梦想与她 提交于 2019-11-26 22:21:58
问题 I'm trying to get my Passport local strategy working. I've got this middleware set up: passport.use(new LocalStrategy(function(username, password, done) { //return done(null, user); if (username=='ben' && password=='benny'){ console.log("Password correct"); return done(null, true); } else return done(null, false, {message: "Incorrect Login"}); })); but then in here app.use('/admin', adminIsLoggedIn, admin); function adminIsLoggedIn(req, res, next) { // if user is authenticated in the session,