[express-jwt] Correct error in callback for secret.

Correct error for secret type in long callback.
Split the callbacks in two interfaces.

Add some test case.
This commit is contained in:
Nicolas Graziano
2018-03-20 18:17:28 +01:00
parent 17c3e0a996
commit 85764dcd2b
2 changed files with 24 additions and 3 deletions

View File

@@ -13,6 +13,25 @@ app.use(jwt({
userProperty: 'auth'
}));
app.use(jwt({
secret: (req: express.Request,
payload: any,
done: (err: any, secret: string) => void) => {
done(null, 'shhhhhhared-secret');
},
userProperty: 'auth'
}));
app.use(jwt({
secret: (req: express.Request,
header: any,
payload: any,
done: (err: any, secret: string) => void) => {
done(null, 'shhhhhhared-secret');
},
userProperty: 'auth'
}));
var jwtCheck = jwt({
secret: 'shhhhhhared-secret'
});
@@ -28,4 +47,4 @@ app.use(function (err: any, req: express.Request, res: express.Response, next: e
} else {
next(err);
}
});
});

View File

@@ -12,8 +12,10 @@ export = jwt;
declare function jwt(options: jwt.Options): jwt.RequestHandler;
declare namespace jwt {
export type secretType = string | Buffer
export interface SecretCallbackLong {
(req: express.Request, header: any, payload: any, done: (err: any, secret?: secretType) => void): void;
}
export interface SecretCallback {
(req: express.Request, header: any, payload: any, done: (err: any, secret?: boolean) => void): void;
(req: express.Request, payload: any, done: (err: any, secret?: secretType) => void): void;
}
@@ -25,7 +27,7 @@ declare namespace jwt {
(req: express.Request): any;
}
export interface Options {
secret: secretType | SecretCallback;
secret: secretType | SecretCallback | SecretCallbackLong;
userProperty?: string;
skip?: string[];
credentialsRequired?: boolean;