Merge pull request #4100 from wjohnsto/master

Fixing #4058 for passport-local by adding support for passReqToCallback = true or false
This commit is contained in:
Masahiro Wakame
2015-04-18 23:22:41 +09:00
2 changed files with 31 additions and 1 deletions
+20
View File
@@ -44,6 +44,26 @@ passport.use(new local.Strategy(function (username, password, done) {
});
}));
passport.use(new local.Strategy({
passReqToCallback: true
}, function (req, username, password, done) {
User.findOne({ username: username }, function (err, user) {
if (err) {
return done(err);
}
if (!user) {
return done(null, false);
}
if (!user.verifyPassword(password)) {
return done(null, false);
}
return done(null, user);
});
}));
// Sample from https://github.com/jaredhanson/passport-local#authenticate-requests
var app = express();
app.post('/login',
+11 -1
View File
@@ -16,16 +16,26 @@ declare module 'passport-local' {
passReqToCallback?: boolean;
}
interface IStrategyOptionsWithRequest {
usernameField?: string;
passwordField?: string;
passReqToCallback: boolean;
}
interface IVerifyOptions {
message: string;
}
interface VerifyFunction {
interface VerifyFunctionWithRequest {
(req: express.Request, username: string, password: string, done: (error: any, user?: any, options?: IVerifyOptions) => void): void;
}
interface VerifyFunction {
(username: string, password: string, done: (error: any, user?: any, options?: IVerifyOptions) => void): void;
}
class Strategy implements passport.Strategy {
constructor(options: IStrategyOptionsWithRequest, verify: VerifyFunctionWithRequest);
constructor(options: IStrategyOptions, verify: VerifyFunction);
constructor(verify: VerifyFunction);