From ce01a4e456fb0f9530d833b8626ed285478909f0 Mon Sep 17 00:00:00 2001 From: Mohsen Azimi Date: Mon, 2 Apr 2018 17:47:15 -0700 Subject: [PATCH] Make stratgey an exported class --- types/passport/index.d.ts | 16 ++++++++-------- types/passport/passport-tests.ts | 12 ++++++++---- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/types/passport/index.d.ts b/types/passport/index.d.ts index 06c7f0b9db..cee220e901 100644 --- a/types/passport/index.d.ts +++ b/types/passport/index.d.ts @@ -5,6 +5,7 @@ // Igor Belagorudsky // Tomek Łaziuk // Daniel Perez Alvarez +// Mohsen Azimi // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 @@ -75,12 +76,15 @@ declare namespace passport { Passport: PassportStatic["Authenticator"]; } - interface Strategy { + /** + * @param T Strategy option config + */ + export abstract class Strategy { name?: string; - authenticate(this: StrategyCreated, req: express.Request, options?: any): any; - } - interface StrategyCreatedStatic { + /** This method must be implemented by the subclass */ + abstract authenticate(req: express.Request, options?: T): any; + /** * Authenticate `user`, with optional `info`. * @@ -124,10 +128,6 @@ declare namespace passport { error(err: any): void; } - type StrategyCreated = { - [P in keyof O]: O[P]; - }; - interface Profile { provider: string; id: string; diff --git a/types/passport/passport-tests.ts b/types/passport/passport-tests.ts index 630091afc7..f7d988c56c 100644 --- a/types/passport/passport-tests.ts +++ b/types/passport/passport-tests.ts @@ -2,14 +2,18 @@ import * as passport from 'passport'; import express = require('express'); import 'express-session'; -class TestStrategy implements passport.Strategy { +class TestStrategy extends passport.Strategy { name = 'test'; - constructor() { } - authenticate(this: passport.StrategyCreated, req: express.Request) { + + authenticate(req: express.Request) { const user: TestUser = { id: 0, }; - this.success(user); + if (Math.random() > 0.5) { + this.fail(); + } else { + this.success(user); + } } }