@villedemontreal/jwt-validator 5.7.11 → 5.7.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,4 +4,4 @@ import * as express from 'express';
4
4
  *
5
5
  * @param {boolean} mandatoryValidation Defines if the JWT is mandatory. Defaults to true.
6
6
  */
7
- export declare const jwtValidationMiddleware: (mandatoryValidation?: boolean) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void>;
7
+ export declare const jwtValidationMiddleware: (mandatoryValidation?: boolean) => (req: express.Request, res: express.Response, next: express.NextFunction) => void;
@@ -10,14 +10,23 @@ const jwtValidator_1 = require("../jwtValidator");
10
10
  * @param {boolean} mandatoryValidation Defines if the JWT is mandatory. Defaults to true.
11
11
  */
12
12
  const jwtValidationMiddleware = (mandatoryValidation = true) => {
13
- return async (req, res, next) => {
13
+ return (req, res, next) => {
14
14
  try {
15
15
  const authHeader = req.get(http_header_fields_typed_1.default.AUTHORIZATION);
16
16
  if (mandatoryValidation || authHeader) {
17
- req[constants_1.constants.requestExtraVariables.JWT] =
18
- await jwtValidator_1.jwtValidator.verifyAuthorizationHeader(authHeader);
17
+ jwtValidator_1.jwtValidator
18
+ .verifyAuthorizationHeader(authHeader)
19
+ .then((jwt) => {
20
+ req[constants_1.constants.requestExtraVariables.JWT] = jwt;
21
+ next();
22
+ })
23
+ .catch((err) => {
24
+ next(err);
25
+ });
26
+ }
27
+ else {
28
+ next();
19
29
  }
20
- next();
21
30
  }
22
31
  catch (err) {
23
32
  next(err);
@@ -1 +1 @@
1
- {"version":3,"file":"jwtMiddleware.js","sourceRoot":"","sources":["../../../src/middleware/jwtMiddleware.ts"],"names":[],"mappings":";;;AACA,uEAA6D;AAC7D,mDAAgD;AAChD,kDAA+C;AAE/C;;;;GAIG;AACI,MAAM,uBAAuB,GAE8D,CAChG,mBAAmB,GAAG,IAAI,EAC1B,EAAE;IACF,OAAO,KAAK,EACV,GAAoB,EACpB,GAAqB,EAC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,IAAI,CAAC,GAAG,CAAC,CAAC;SACX;IACH,CAAC,CAAC;AACJ,CAAC,CAAC;AAzBW,QAAA,uBAAuB,2BAyBlC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@villedemontreal/jwt-validator",
3
- "version": "5.7.11",
3
+ "version": "5.7.12",
4
4
  "description": "Module to validate JWT (JSON Web Tokens)",
5
5
  "main": "dist/src/index.js",
6
6
  "typings": "dist/src",
@@ -10,21 +10,25 @@ import { jwtValidator } from '../jwtValidator';
10
10
  */
11
11
  export const jwtValidationMiddleware: (
12
12
  mandatoryValidation?: boolean
13
- ) => (req: express.Request, res: express.Response, next: express.NextFunction) => Promise<void> = (
13
+ ) => (req: express.Request, res: express.Response, next: express.NextFunction) => void = (
14
14
  mandatoryValidation = true
15
15
  ) => {
16
- return async (
17
- req: express.Request,
18
- res: express.Response,
19
- next: express.NextFunction
20
- ): Promise<void> => {
16
+ return (req: express.Request, res: express.Response, next: express.NextFunction): void => {
21
17
  try {
22
18
  const authHeader: string = req.get(httpHeaderFieldsTyped.AUTHORIZATION);
23
19
  if (mandatoryValidation || authHeader) {
24
- (req as any)[constants.requestExtraVariables.JWT] =
25
- await jwtValidator.verifyAuthorizationHeader(authHeader);
20
+ jwtValidator
21
+ .verifyAuthorizationHeader(authHeader)
22
+ .then((jwt) => {
23
+ (req as any)[constants.requestExtraVariables.JWT] = jwt;
24
+ next();
25
+ })
26
+ .catch((err) => {
27
+ next(err);
28
+ });
29
+ } else {
30
+ next();
26
31
  }
27
- next();
28
32
  } catch (err) {
29
33
  next(err);
30
34
  }