function Strategy(options, verify) { if (typeof options == 'function') { verify = options; options = {}; } if (!verify) { throw new TypeError('LocalStrategy requires a verify callback'); } this._usernameField = options.usernameField || 'username'; this._passwordField = options.passwordField || 'password'; passport.Strategy.call(this); this.name = 'local'; this._verify = verify; this._passReqToCallback = options.passReqToCallback; }
n/a
function Strategy(options, verify) { if (typeof options == 'function') { verify = options; options = {}; } if (!verify) { throw new TypeError('LocalStrategy requires a verify callback'); } this._usernameField = options.usernameField || 'username'; this._passwordField = options.passwordField || 'password'; passport.Strategy.call(this); this.name = 'local'; this._verify = verify; this._passReqToCallback = options.passReqToCallback; }
n/a
function Strategy() { }
n/a
function Strategy(options, verify) { if (typeof options == 'function') { verify = options; options = {}; } if (!verify) { throw new TypeError('LocalStrategy requires a verify callback'); } this._usernameField = options.usernameField || 'username'; this._passwordField = options.passwordField || 'password'; passport.Strategy.call(this); this.name = 'local'; this._verify = verify; this._passReqToCallback = options.passReqToCallback; }
n/a
function Strategy() { }
n/a
authenticate = function (req, options) { options = options || {}; var username = lookup(req.body, this._usernameField) || lookup(req.query, this._usernameField); var password = lookup(req.body, this._passwordField) || lookup(req.query, this._passwordField); if (!username || !password) { return this.fail({ message: options.badRequestMessage || 'Missing credentials' }, 400); } var self = this; function verified(err, user, info) { if (err) { return self.error(err); } if (!user) { return self.fail(info); } self.success(user, info); } try { if (self._passReqToCallback) { this._verify(req, username, password, verified); } else { this._verify(username, password, verified); } } catch (ex) { return self.error(ex); } }
...
return done(null, user);
});
}
));
#### Authenticate Requests
Use `passport.authenticate()`, specifying the `'local'` strategy, to
authenticate requests.
For example, as route middleware in an [Express](http://expressjs.com/)
application:
app.post('/login',
passport.authenticate('local', { failureRedirect: '/login' }),
...
function Strategy() { }
n/a
function Strategy() { }
n/a
authenticate = function (req, options) { throw new Error('Strategy#authenticate must be overridden by subclass'); }
...
return done(null, user);
});
}
));
#### Authenticate Requests
Use `passport.authenticate()`, specifying the `'local'` strategy, to
authenticate requests.
For example, as route middleware in an [Express](http://expressjs.com/)
application:
app.post('/login',
passport.authenticate('local', { failureRedirect: '/login' }),
...