diff --git a/passport-local/passport-local-tests.ts b/passport-local/passport-local-tests.ts index de799a4d8..f462846b8 100644 --- a/passport-local/passport-local-tests.ts +++ b/passport-local/passport-local-tests.ts @@ -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', diff --git a/passport-local/passport-local.d.ts b/passport-local/passport-local.d.ts index d61e51b15..34fca8194 100644 --- a/passport-local/passport-local.d.ts +++ b/passport-local/passport-local.d.ts @@ -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);