Merge pull request #31432 from kstiehl/master

[passport] - consitent typing of options passed to authorize & authenticate
This commit is contained in:
Wesley Wigham
2018-12-24 21:35:36 -08:00
committed by GitHub
2 changed files with 10 additions and 3 deletions
+4 -3
View File
@@ -1,10 +1,11 @@
// Type definitions for Passport 0.4
// Type definitions for Passport 1.0
// Project: http://passportjs.org
// Definitions by: Horiuchi_H <https://github.com/horiuchi>
// Eric Naeseth <https://github.com/enaeseth>
// Igor Belagorudsky <https://github.com/theigor>
// Tomek Łaziuk <https://github.com/tlaziuk>
// Daniel Perez Alvarez <https://github.com/danielpa9708>
// Kevin Stiehl <https://github.com/kstiehl>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
@@ -52,7 +53,7 @@ declare namespace passport {
prompt?: string;
}
interface Authenticator<InitializeRet = express.Handler, AuthenticateRet = any, AuthorizeRet = AuthenticateRet> {
interface Authenticator<InitializeRet = express.Handler, AuthenticateRet = any, AuthorizeRet = AuthenticateRet, AuthorizeOptions = AuthenticateOptions> {
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<TUser, TID>(fn: (user: TUser, done: (err: any, id?: TID) => void) => void): void;
deserializeUser<TUser, TID>(fn: (id: TID, done: (err: any, user?: TUser) => void) => void): void;
transformAuthInfo(fn: (info: any, done: (err: any, info: any) => void) => void): void;
+6
View File
@@ -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); }