From 23125db9f2630e6ae7689f274933dc6348a419cc Mon Sep 17 00:00:00 2001 From: Kevin Date: Sat, 15 Dec 2018 21:37:51 +0100 Subject: [PATCH] passport - auhtorize & authenticate consistency --- types/passport/index.d.ts | 7 ++++--- types/passport/passport-tests.ts | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/types/passport/index.d.ts b/types/passport/index.d.ts index 1a8afed691..17aa846946 100644 --- a/types/passport/index.d.ts +++ b/types/passport/index.d.ts @@ -1,10 +1,11 @@ -// Type definitions for Passport 0.4 +// Type definitions for Passport 1.0 // Project: http://passportjs.org // Definitions by: Horiuchi_H // Eric Naeseth // Igor Belagorudsky // Tomek Łaziuk // Daniel Perez Alvarez +// Kevin Stiehl // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -52,7 +53,7 @@ declare namespace passport { prompt?: string; } - interface Authenticator { + interface Authenticator { use(strategy: Strategy): this; use(name: string, strategy: Strategy): this; unuse(name: string): this; @@ -63,7 +64,7 @@ declare namespace passport { authenticate(strategy: string | string[], callback?: (...args: any[]) => any): AuthenticateRet; authenticate(strategy: string | string[], options: AuthenticateOptions, callback?: (...args: any[]) => any): AuthenticateRet; authorize(strategy: string | string[], callback?: (...args: any[]) => any): AuthorizeRet; - authorize(strategy: string | string[], options: any, callback?: (...args: any[]) => any): AuthorizeRet; + authorize(strategy: string | string[], options: AuthorizeOptions, callback?: (...args: any[]) => any): AuthorizeRet; serializeUser(fn: (user: TUser, done: (err: any, id?: TID) => void) => void): void; deserializeUser(fn: (id: TID, done: (err: any, user?: TUser) => void) => void): void; transformAuthInfo(fn: (info: any, done: (err: any, info: any) => void) => void): void; diff --git a/types/passport/passport-tests.ts b/types/passport/passport-tests.ts index f7d988c56c..2e7d003291 100644 --- a/types/passport/passport-tests.ts +++ b/types/passport/passport-tests.ts @@ -78,6 +78,12 @@ app.post('/login', res.redirect('/'); }); +app.post('/login', + passport.authorize('local', { failureRedirect: '/login', failureFlash: true }), + (req, res) => { + res.redirect('/'); + }); + app.post('/login', (req, res, next) => { passport.authenticate('local', (err: any, user: { username: string; }, info: { message: string; }) => { if (err) { return next(err); }