From 1565c8972713695300d1ef475bc14e762f19f2db Mon Sep 17 00:00:00 2001 From: Will Johnston Date: Mon, 13 Apr 2015 18:24:43 -0500 Subject: [PATCH 1/2] fixed passport-local typings to allow for two different verify functions, added test --- passport-local/passport-local-tests.ts | 20 ++++++++++++++++++++ passport-local/passport-local.d.ts | 11 +++++++++++ 2 files changed, 31 insertions(+) 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 6b3cbef38..a2bec8daf 100644 --- a/passport-local/passport-local.d.ts +++ b/passport-local/passport-local.d.ts @@ -15,15 +15,26 @@ declare module 'passport-local' { passwordField?: string; } + interface IStrategyOptionsWithRequest { + usernameField?: string; + passwordField?: string; + passReqToCallback: boolean; + } + interface IVerifyOptions { message: string; } + 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); From 67e09fcdb1efacbb3abf964672b4b362f0e68b4b Mon Sep 17 00:00:00 2001 From: Will Johnston Date: Mon, 13 Apr 2015 18:37:09 -0500 Subject: [PATCH 2/2] removing unnecessary definition --- passport-local/passport-local.d.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/passport-local/passport-local.d.ts b/passport-local/passport-local.d.ts index 2fc62dc7b..34fca8194 100644 --- a/passport-local/passport-local.d.ts +++ b/passport-local/passport-local.d.ts @@ -31,7 +31,6 @@ declare module 'passport-local' { } interface VerifyFunction { - (req: express.Request, username: string, password: string, done: (error: any, user?: any, options?: IVerifyOptions) => void): void; (username: string, password: string, done: (error: any, user?: any, options?: IVerifyOptions) => void): void; }