From b349285311741c25d1e3acf75ee3591477314cc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Tue, 6 Feb 2018 00:07:42 +0100 Subject: [PATCH 1/4] passport-http fix --- types/passport-http/index.d.ts | 8 ++- types/passport-http/passport-http-tests.ts | 28 ++++---- types/passport-http/tslint.json | 78 +--------------------- 3 files changed, 20 insertions(+), 94 deletions(-) diff --git a/types/passport-http/index.d.ts b/types/passport-http/index.d.ts index e9a66964ea..aedb119fa0 100644 --- a/types/passport-http/index.d.ts +++ b/types/passport-http/index.d.ts @@ -1,15 +1,16 @@ // Type definitions for passport-http 0.3.0 // Project: https://github.com/jaredhanson/passport-http // Definitions by: Christophe Vidal +// Tomek Łaziuk // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 import passport = require("passport"); import express = require("express"); -interface BasicStrategyOptions { +interface BasicStrategyOptions { realm?: string; - passReqToCallback?: boolean; + passReqToCallback?: req; } interface DigestStrategyOptions { @@ -45,7 +46,8 @@ interface DigestValidateFunction { declare class BasicStrategy implements passport.Strategy { constructor(verify: BasicVerifyFunction); - constructor(options: BasicStrategyOptions, verify: BasicVerifyFunction); + constructor(options: BasicStrategyOptions, verify: BasicVerifyFunction); + constructor(options: BasicStrategyOptions, verify: BasicVerifyFunctionWithRequest); name: string; authenticate: (req: express.Request, options?: Object) => void; diff --git a/types/passport-http/passport-http-tests.ts b/types/passport-http/passport-http-tests.ts index 4a70d30b89..217bb5e289 100644 --- a/types/passport-http/passport-http-tests.ts +++ b/types/passport-http/passport-http-tests.ts @@ -24,7 +24,7 @@ function validateNonce(nonce: string) { function validateParams(nonce: string, cnonce: string, nc: number, opaque: string) { } -passport.use(new http.BasicStrategy((username: string, password: string, done: any) => { +passport.use(new http.BasicStrategy((username, password, done) => { User.findOne({ username: username, password: password, @@ -44,21 +44,21 @@ passport.use(new http.BasicStrategy((username: string, password: string, done: a passport.use(new http.BasicStrategy({ realm: "User", passReqToCallback: true, -}, (username: string, password: string, done: any) => { - User.findOne({ - username: username, - password: password, - }, (error, user) => { - if (error) { - return done(error); - } +}, (req, username, password, done) => { + // with req when needed +})); - if (!user) { - return done(null, false); - } +passport.use(new http.BasicStrategy({ + realm: "User", +}, (username, password, done) => { + // without req by default +})); - done(null, user); - }); +passport.use(new http.BasicStrategy({ + realm: "User", + passReqToCallback: false, +}, (username, password, done) => { + // without req })); passport.use(new http.DigestStrategy((username: string, done: any) => { diff --git a/types/passport-http/tslint.json b/types/passport-http/tslint.json index a41bf5d19a..f93cf8562a 100644 --- a/types/passport-http/tslint.json +++ b/types/passport-http/tslint.json @@ -1,79 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } + "extends": "dtslint/dt.json" } From 622186f74f4d83f502cc183fc2abc0bf31cb02f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Tue, 6 Feb 2018 00:20:49 +0100 Subject: [PATCH 2/4] tslint --- types/passport-http/index.d.ts | 55 ++++++++++++---------- types/passport-http/passport-http-tests.ts | 22 ++++----- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/types/passport-http/index.d.ts b/types/passport-http/index.d.ts index aedb119fa0..bb9dd35c1b 100644 --- a/types/passport-http/index.d.ts +++ b/types/passport-http/index.d.ts @@ -1,62 +1,69 @@ -// Type definitions for passport-http 0.3.0 +// Type definitions for passport-http 0.3 // Project: https://github.com/jaredhanson/passport-http // Definitions by: Christophe Vidal // Tomek Łaziuk // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 -import passport = require("passport"); -import express = require("express"); +import * as passport from "passport"; +import * as express from "express"; -interface BasicStrategyOptions { +export interface BasicStrategyOptions { realm?: string; passReqToCallback?: req; } -interface DigestStrategyOptions { +export interface DigestStrategyOptions { realm?: string; - domain?: string | Array; + domain?: string | string[]; opaque?: string; algorithm?: string; - qop?: string | Array; + qop?: string | string[]; } -interface DigestValidateOptions { +export interface DigestValidateOptions { nonce: string; cnonce: string; nc: number; opaque: string; } -interface BasicVerifyFunction { - (username: string, password: string, done: (error: any, user?: any) => void): void; -} +export type BasicVerifyFunction = ( + username: string, + password: string, + done: (error: any, user?: any) => void, +) => any; -interface BasicVerifyFunctionWithRequest { - (req: express.Request, username: string, password: string, done: (error: any, user?: any) => void): void; -} +export type BasicVerifyFunctionWithRequest = ( + req: express.Request, + username: string, + password: string, + done: (error: any, user?: any) => void, +) => any; -interface DigestSecretFunction { - (username: string, done: (error: any, user?: any, password?: any) => void): void; -} +export type DigestSecretFunction = ( + username: string, + done: (error: any, user?: any, password?: any) => void, +) => any; -interface DigestValidateFunction { - (params: DigestValidateOptions, done: (error: any, valid: boolean) => void): void; -} +export type DigestValidateFunction = ( + params: DigestValidateOptions, + done: (error: any, valid: boolean) => void, +) => any; -declare class BasicStrategy implements passport.Strategy { +export class BasicStrategy implements passport.Strategy { constructor(verify: BasicVerifyFunction); constructor(options: BasicStrategyOptions, verify: BasicVerifyFunction); constructor(options: BasicStrategyOptions, verify: BasicVerifyFunctionWithRequest); name: string; - authenticate: (req: express.Request, options?: Object) => void; + authenticate: (req: express.Request, options?: object) => void; } -declare class DigestStrategy implements passport.Strategy { +export declare class DigestStrategy implements passport.Strategy { constructor(secret: DigestSecretFunction, validate?: DigestValidateFunction); constructor(options: DigestStrategyOptions, secret: DigestSecretFunction, validate?: DigestValidateFunction); name: string; - authenticate: (req: express.Request, options?: Object) => void; + authenticate: (req: express.Request, options?: object) => void; } diff --git a/types/passport-http/passport-http-tests.ts b/types/passport-http/passport-http-tests.ts index 217bb5e289..a9e09b0df1 100644 --- a/types/passport-http/passport-http-tests.ts +++ b/types/passport-http/passport-http-tests.ts @@ -2,18 +2,18 @@ * Created by Christophe Vidal */ -import passport = require("passport"); -import http = require("passport-http"); +import * as passport from "passport"; +import * as http from "passport-http"; -interface IUser { +interface UserInterface { username: string; password?: string; } class User { - public password: string; + password: string; - static findOne(user: IUser, callback: (error: Error, user: User) => void): void { + static findOne(user: UserInterface, callback: (error: Error, user: User) => void): void { callback(null, new User()); } } @@ -26,8 +26,8 @@ function validateParams(nonce: string, cnonce: string, nc: number, opaque: strin passport.use(new http.BasicStrategy((username, password, done) => { User.findOne({ - username: username, - password: password, + username, + password, }, (error, user) => { if (error) { return done(error); @@ -62,7 +62,7 @@ passport.use(new http.BasicStrategy({ })); passport.use(new http.DigestStrategy((username: string, done: any) => { - User.findOne({username: username}, (error, user) => { + User.findOne({username}, (error, user) => { if (error) { return done(error); } @@ -76,7 +76,7 @@ passport.use(new http.DigestStrategy((username: string, done: any) => { })); passport.use(new http.DigestStrategy((username: string, done: any) => { - User.findOne({username: username}, (error, user) => { + User.findOne({username}, (error, user) => { if (error) { return done(error); } @@ -99,7 +99,7 @@ passport.use(new http.DigestStrategy({ algorithm: "MD5", qop: "auth", }, (username: string, done: any) => { - User.findOne({username: username}, (error, user) => { + User.findOne({username}, (error, user) => { if (error) { return done(error); } @@ -119,7 +119,7 @@ passport.use(new http.DigestStrategy({ algorithm: "MD5", qop: "auth", }, (username: string, done: any) => { - User.findOne({username: username}, (error, user) => { + User.findOne({username}, (error, user) => { if (error) { return done(error); } From c1fb0e4ba8d3edd6727c62d74ade911fa887ab12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Tue, 6 Feb 2018 00:23:06 +0100 Subject: [PATCH 3/4] esModuleInterlop --- types/passport-http/index.d.ts | 4 ++-- types/passport-http/passport-http-tests.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/types/passport-http/index.d.ts b/types/passport-http/index.d.ts index bb9dd35c1b..bee5e37f33 100644 --- a/types/passport-http/index.d.ts +++ b/types/passport-http/index.d.ts @@ -5,8 +5,8 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // TypeScript Version: 2.3 -import * as passport from "passport"; -import * as express from "express"; +import passport = require("passport"); +import http = require("passport-http"); export interface BasicStrategyOptions { realm?: string; diff --git a/types/passport-http/passport-http-tests.ts b/types/passport-http/passport-http-tests.ts index a9e09b0df1..9db1439faa 100644 --- a/types/passport-http/passport-http-tests.ts +++ b/types/passport-http/passport-http-tests.ts @@ -2,8 +2,8 @@ * Created by Christophe Vidal */ -import * as passport from "passport"; -import * as http from "passport-http"; +import passport = require("passport"); +import http = require("passport-http"); interface UserInterface { username: string; @@ -62,7 +62,7 @@ passport.use(new http.BasicStrategy({ })); passport.use(new http.DigestStrategy((username: string, done: any) => { - User.findOne({username}, (error, user) => { + User.findOne({ username }, (error, user) => { if (error) { return done(error); } @@ -76,7 +76,7 @@ passport.use(new http.DigestStrategy((username: string, done: any) => { })); passport.use(new http.DigestStrategy((username: string, done: any) => { - User.findOne({username}, (error, user) => { + User.findOne({ username }, (error, user) => { if (error) { return done(error); } @@ -99,7 +99,7 @@ passport.use(new http.DigestStrategy({ algorithm: "MD5", qop: "auth", }, (username: string, done: any) => { - User.findOne({username}, (error, user) => { + User.findOne({ username }, (error, user) => { if (error) { return done(error); } @@ -119,7 +119,7 @@ passport.use(new http.DigestStrategy({ algorithm: "MD5", qop: "auth", }, (username: string, done: any) => { - User.findOne({username}, (error, user) => { + User.findOne({ username }, (error, user) => { if (error) { return done(error); } From 35b9ca92d24402bc970620aa23492da1a7fe991a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20=C5=81aziuk?= Date: Tue, 6 Feb 2018 00:29:10 +0100 Subject: [PATCH 4/4] tslint --- types/passport-http/index.d.ts | 4 ++-- types/passport-http/passport-http-tests.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/types/passport-http/index.d.ts b/types/passport-http/index.d.ts index bee5e37f33..458e5f2076 100644 --- a/types/passport-http/index.d.ts +++ b/types/passport-http/index.d.ts @@ -6,7 +6,7 @@ // TypeScript Version: 2.3 import passport = require("passport"); -import http = require("passport-http"); +import express = require("express"); export interface BasicStrategyOptions { realm?: string; @@ -60,7 +60,7 @@ export class BasicStrategy implements passport.Strategy { authenticate: (req: express.Request, options?: object) => void; } -export declare class DigestStrategy implements passport.Strategy { +export class DigestStrategy implements passport.Strategy { constructor(secret: DigestSecretFunction, validate?: DigestValidateFunction); constructor(options: DigestStrategyOptions, secret: DigestSecretFunction, validate?: DigestValidateFunction); diff --git a/types/passport-http/passport-http-tests.ts b/types/passport-http/passport-http-tests.ts index 9db1439faa..396138b466 100644 --- a/types/passport-http/passport-http-tests.ts +++ b/types/passport-http/passport-http-tests.ts @@ -30,11 +30,13 @@ passport.use(new http.BasicStrategy((username, password, done) => { password, }, (error, user) => { if (error) { - return done(error); + done(error); + return; } if (!user) { - return done(null, false); + done(null, false); + return; } done(null, user);