mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 14:27:04 +00:00
Merge pull request #23444 from tlaziuk/passport-http
[passport-http] fix BasicStrategy
This commit is contained in:
Vendored
+33
-24
@@ -1,60 +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 <https://github.com/krizalys>
|
||||
// Tomek Łaziuk <https://github.com/tlaziuk>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
import passport = require("passport");
|
||||
import express = require("express");
|
||||
|
||||
interface BasicStrategyOptions {
|
||||
export interface BasicStrategyOptions<req extends boolean = boolean> {
|
||||
realm?: string;
|
||||
passReqToCallback?: boolean;
|
||||
passReqToCallback?: req;
|
||||
}
|
||||
|
||||
interface DigestStrategyOptions {
|
||||
export interface DigestStrategyOptions {
|
||||
realm?: string;
|
||||
domain?: string | Array<string>;
|
||||
domain?: string | string[];
|
||||
opaque?: string;
|
||||
algorithm?: string;
|
||||
qop?: string | Array<string>;
|
||||
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<false>, verify: BasicVerifyFunction);
|
||||
constructor(options: BasicStrategyOptions<true>, 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 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;
|
||||
}
|
||||
|
||||
@@ -5,15 +5,15 @@
|
||||
import passport = require("passport");
|
||||
import http = require("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());
|
||||
}
|
||||
}
|
||||
@@ -24,17 +24,19 @@ 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,
|
||||
username,
|
||||
password,
|
||||
}, (error, user) => {
|
||||
if (error) {
|
||||
return done(error);
|
||||
done(error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!user) {
|
||||
return done(null, false);
|
||||
done(null, false);
|
||||
return;
|
||||
}
|
||||
|
||||
done(null, user);
|
||||
@@ -44,25 +46,25 @@ 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) => {
|
||||
User.findOne({username: username}, (error, user) => {
|
||||
User.findOne({ username }, (error, user) => {
|
||||
if (error) {
|
||||
return done(error);
|
||||
}
|
||||
@@ -76,7 +78,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 +101,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 +121,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);
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user