mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 15:57:13 +00:00
Make stratgey an exported class
This commit is contained in:
Vendored
+8
-8
@@ -5,6 +5,7 @@
|
||||
// Igor Belagorudsky <https://github.com/theigor>
|
||||
// Tomek Łaziuk <https://github.com/tlaziuk>
|
||||
// Daniel Perez Alvarez <https://github.com/danielpa9708>
|
||||
// Mohsen Azimi <https://github.com/mohsen1>
|
||||
// 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<T = object> {
|
||||
name?: string;
|
||||
authenticate(this: StrategyCreated<this>, 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<T, O = T & StrategyCreatedStatic> = {
|
||||
[P in keyof O]: O[P];
|
||||
};
|
||||
|
||||
interface Profile {
|
||||
provider: string;
|
||||
id: string;
|
||||
|
||||
@@ -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<this>, 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user