@carecard/jwt-read 1.0.5 → 3.0.1

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.
package/index.js ADDED
@@ -0,0 +1,21 @@
1
+ const jwtLib = require( './lib/jwtLib' );
2
+ const jwtRoles = require( './lib/jwtRoles' );
3
+
4
+
5
+ module.exports = {
6
+ verifyJwt: jwtLib.verifyJwt,
7
+ verifyWebToken: jwtLib.verifyWebToken,
8
+ verifyJwtNoThrow: jwtLib.verifyJwtNoThrow,
9
+ verifyWebTokenNoThrow: jwtLib.verifyWebTokenNoThrow,
10
+ verifyVisitorNoThrow: jwtLib.verifyVisitorNoThrow,
11
+ jwtClientId: jwtLib.jwtClientId,
12
+ visitorClientId: jwtLib.visitorClientId,
13
+ isJwtExpired: jwtLib.isJwtExpired,
14
+ jwtAgeInSeconds: jwtLib.jwtAgeInSeconds,
15
+ verifyJwtAndRole: jwtLib.verifyJwtAndRole,
16
+ throwUsedTokenError: jwtLib.throwUsedTokenError,
17
+ doesJwtUserHasRole: jwtLib.doesJwtUserHasRole,
18
+ getNameOfRole: jwtRoles.getNameOfRoleFromCode,
19
+ getCodeOfRole: jwtRoles.getCodeFromNameOfRole
20
+ };
21
+
package/lib/jwtLib.js ADDED
@@ -0,0 +1,475 @@
1
+ const validate = require( '@carecard/validate' ).validate;
2
+ const { jwtUtilAuth } = require( '@carecard/auth-util' );
3
+ const {
4
+ throwLoginRequiredError,
5
+ throwNotAuthorizedError
6
+ } = require( "@carecard/common-util" ).error;
7
+
8
+ function jwtClientId( req ) {
9
+ const jwtObj = req?.jwt || this;
10
+ return jwtObj?.payload?.client_id;
11
+ }
12
+
13
+ function visitorClientId( req ) {
14
+ const visitorObj = req?.visitor || this;
15
+ return visitorObj?.payload?.client_id;
16
+ }
17
+
18
+ function doesJwtUserHasRole( req, userRole ) {
19
+ // Check if called as req.jwt.doesJwtUserHasRole(userRole) or doesJwtUserHasRole(role)
20
+ if ( arguments.length === 1 && typeof req === 'string' ) {
21
+ userRole = req;
22
+ req = undefined;
23
+ }
24
+
25
+ const jwtObj = req?.jwt || this;
26
+
27
+ if ( userRole && typeof userRole === "string" ) {
28
+ return jwtObj?.payload?.roles?.includes( userRole );
29
+ } else {
30
+ throwNotAuthorizedError();
31
+ }
32
+ }
33
+
34
+ function throwError( customErrorFunction ) {
35
+ ( typeof customErrorFunction === "function" ) ?
36
+ customErrorFunction() :
37
+ throwLoginRequiredError()
38
+ }
39
+
40
+ function isJwtExpired( req, jwtValiditySeconds ) {
41
+ // Check if called as req.jwt.isJwtExpired(seconds) or isJwtExpired(seconds)
42
+ if ( arguments.length === 1 && typeof req === 'number' ) {
43
+ jwtValiditySeconds = req;
44
+ req = undefined;
45
+ }
46
+
47
+ if ( jwtValiditySeconds && typeof jwtValiditySeconds === "number" ) {
48
+ return ( parseInt( jwtValiditySeconds ) ) < jwtAgeInSeconds.call( this, req );
49
+ } else {
50
+ return true;
51
+ }
52
+
53
+ }
54
+
55
+ function jwtAgeInSeconds( req ) {
56
+ const jwtObj = req?.jwt || this;
57
+
58
+ if ( jwtObj?.payload?.iat ) {
59
+
60
+ let iat = jwtObj.payload.iat;
61
+ if ( iat > 1000000000000 ) {
62
+ iat = Math.floor( iat / 1000 );
63
+ }
64
+
65
+ jwtObj[ "age" ] = Math.floor( Date.now() / 1000 ) - iat;
66
+ return jwtObj.age;
67
+
68
+ } else {
69
+
70
+ jwtObj[ "age" ] = Infinity
71
+ return jwtObj.age;
72
+
73
+ }
74
+ }
75
+
76
+ async function validateAndExtractJwtObject( req, publicKey, customErrorFunction ) {
77
+
78
+ const jwtString = await _validateJwt( req, customErrorFunction );
79
+
80
+ const isJwtSignatureValid = await _isJwtSignatureValid( jwtString, publicKey, customErrorFunction );
81
+
82
+ if ( jwtString && isJwtSignatureValid ) {
83
+ await _extractJwtObject( req, jwtString, customErrorFunction );
84
+ } else {
85
+ req[ "jwt" ] = null;
86
+ throwError( customErrorFunction );
87
+ }
88
+
89
+ return req;
90
+ }
91
+
92
+ async function validateAndExtractWebToken( req, publicKey, headerName, customErrorFunction ) {
93
+
94
+ const webTokenString = await _validateWebToken( req, headerName, customErrorFunction );
95
+
96
+ const isJwtSignatureValid = await _isJwtSignatureValid( webTokenString, publicKey, customErrorFunction );
97
+
98
+ if ( webTokenString && isJwtSignatureValid ) {
99
+ await _extractJwtObject( req, webTokenString, customErrorFunction );
100
+ } else {
101
+ req[ "jwt" ] = null;
102
+ throwError( customErrorFunction );
103
+ }
104
+
105
+ return req;
106
+ }
107
+
108
+ async function validateAndExtractJwtObjectNoThrow( req, publicKey ) {
109
+
110
+ try {
111
+
112
+ const jwtString = await _validateJwtNoThrow( req );
113
+
114
+ const isJwtSignatureValid = await _isJwtSignatureValidNoThrow( jwtString, publicKey );
115
+
116
+ if ( jwtString && isJwtSignatureValid ) {
117
+ await _extractJwtObjectNoThrow( req, jwtString );
118
+ } else {
119
+ req[ "jwt" ] = null;
120
+ }
121
+
122
+ } catch ( err ) {
123
+
124
+ req[ "jwt" ] = null;
125
+
126
+ }
127
+
128
+ return req;
129
+ }
130
+
131
+ async function validateAndExtractWebTokenObjectNoThrow( req, publicKey, headerName ) {
132
+
133
+ try {
134
+
135
+ const jwtString = _validateWebTokenNoThrow( req, headerName );
136
+
137
+ const isJwtSignatureValid = await _isJwtSignatureValidNoThrow( jwtString, publicKey );
138
+
139
+ if ( jwtString && isJwtSignatureValid ) {
140
+ await _extractJwtObjectNoThrow( req, jwtString );
141
+ } else {
142
+ req[ "jwt" ] = null;
143
+ }
144
+
145
+ } catch ( err ) {
146
+
147
+ req[ "jwt" ] = null;
148
+
149
+ }
150
+
151
+ return req;
152
+ }
153
+
154
+ async function validateAndExtractVisitorObjectNoThrow( req, publicKey ) {
155
+
156
+ try {
157
+
158
+ const jwtString = await _validateVisitorNoThrow( req );
159
+
160
+ const isJwtSignatureValid = await _isJwtSignatureValidNoThrow( jwtString, publicKey );
161
+
162
+ if ( jwtString && isJwtSignatureValid ) {
163
+ await _extractVisitorObjectNoThrow( req, jwtString );
164
+ } else {
165
+ req[ "visitor" ] = null;
166
+ }
167
+
168
+ } catch ( err ) {
169
+
170
+ req[ "visitor" ] = null;
171
+
172
+ }
173
+
174
+ return req;
175
+ }
176
+
177
+ function verifyJwtAndRole( role, publicKey, customErrorFunction ) {
178
+ return async function ( req, res, next ) {
179
+ await validateAndExtractJwtObject( req, publicKey, customErrorFunction )
180
+ .then( req => doesJwtUserHasRole( req, role ) )
181
+ .then( isRoleExist => _isLoginRequired( isRoleExist, customErrorFunction ) )
182
+ .then( () => next() )
183
+ .catch( next );
184
+ }
185
+ }
186
+
187
+ function verifyJwt( publicKey, customErrorFunction ) {
188
+ return async function ( req, res, next ) {
189
+ await validateAndExtractJwtObject( req, publicKey, customErrorFunction )
190
+ .then( () => process.nextTick( next ) )
191
+ .catch( next );
192
+ }
193
+ }
194
+
195
+ function verifyWebToken( publicKey, headerName, customErrorFunction ) {
196
+ return async function ( req, res, next ) {
197
+ await validateAndExtractWebToken( req, publicKey, headerName, customErrorFunction )
198
+ .then( () => process.nextTick( next ) )
199
+ .catch( next );
200
+ }
201
+ }
202
+
203
+ function verifyJwtNoThrow( publicKey ) {
204
+ return async function ( req, res, next ) {
205
+ await validateAndExtractJwtObjectNoThrow( req, publicKey )
206
+ .then( () => process.nextTick( next ) )
207
+ .catch( next );
208
+ }
209
+ }
210
+
211
+ function verifyWebTokenNoThrow( publicKey, headerName ) {
212
+ return async function ( req, res, next ) {
213
+ await validateAndExtractWebTokenObjectNoThrow( req, publicKey, headerName )
214
+ .then( () => process.nextTick( next ) )
215
+ .catch( next );
216
+ }
217
+ }
218
+
219
+ function verifyVisitorNoThrow( publicKey ) {
220
+ return async function ( req, res, next ) {
221
+ await validateAndExtractVisitorObjectNoThrow( req, publicKey )
222
+ .then( () => process.nextTick( next ) )
223
+ .catch( next );
224
+ }
225
+ }
226
+
227
+ function throwUsedTokenError() {
228
+ throw new Error( "Used_Token" );
229
+ }
230
+
231
+ /*********************
232
+ * Private functions *
233
+ *********************/
234
+ function _isLoginRequired( hasRequiredRole, customErrorFunction ) {
235
+
236
+ if ( !hasRequiredRole ) {
237
+ throwError( customErrorFunction );
238
+ }
239
+
240
+ }
241
+
242
+ async function _extractJwtObject( req, jwt, customErrorFunction ) {
243
+ if ( jwt && typeof jwt === "string" ) {
244
+ const jwtObj = jwtUtilAuth.getHeaderPayloadFromJwt( jwt );
245
+ _attachJwtMethods( jwtObj );
246
+ req[ "jwt" ] = jwtObj;
247
+ } else {
248
+ throwError( customErrorFunction );
249
+ }
250
+ }
251
+
252
+ async function _extractJwtObjectNoThrow( req, jwt ) {
253
+ if ( jwt && typeof jwt === "string" ) {
254
+ const jwtObj = jwtUtilAuth.getHeaderPayloadFromJwt( jwt );
255
+ _attachJwtMethods( jwtObj );
256
+ req[ "jwt" ] = jwtObj;
257
+ } else {
258
+ req[ "jwt" ] = null;
259
+ }
260
+ }
261
+
262
+ async function _extractVisitorObjectNoThrow( req, jwt ) {
263
+ if ( jwt && typeof jwt === "string" ) {
264
+ const visitorObj = jwtUtilAuth.getHeaderPayloadFromJwt( jwt );
265
+ _attachVisitorMethods( visitorObj );
266
+ req[ "visitor" ] = visitorObj;
267
+ } else {
268
+ req[ "visitor" ] = null;
269
+ }
270
+ }
271
+
272
+ function _attachJwtMethods( jwtObj ) {
273
+ if ( jwtObj ) {
274
+ Object.defineProperties( jwtObj, {
275
+ jwtClientId: { value: jwtClientId, enumerable: false },
276
+ doesJwtUserHasRole: { value: doesJwtUserHasRole, enumerable: false },
277
+ isJwtExpired: { value: isJwtExpired, enumerable: false },
278
+ jwtAgeInSeconds: { value: jwtAgeInSeconds, enumerable: false }
279
+ } );
280
+ }
281
+ }
282
+
283
+ function _attachVisitorMethods( visitorObj ) {
284
+ if ( visitorObj ) {
285
+ Object.defineProperties( visitorObj, {
286
+ visitorClientId: { value: visitorClientId, enumerable: false }
287
+ } );
288
+ }
289
+ }
290
+
291
+ async function _isJwtSignatureValid( jwt, publicKey, customErrorFunction ) {
292
+
293
+ if ( jwt && typeof jwt === "string" ) {
294
+ return jwtUtilAuth.verifyJwtSignature( jwt, publicKey )
295
+ } else {
296
+ throwError( customErrorFunction );
297
+ }
298
+ }
299
+
300
+ async function _isJwtSignatureValidNoThrow( jwt, publicKey ) {
301
+
302
+ if ( jwt && typeof jwt === "string" ) {
303
+ return jwtUtilAuth.verifyJwtSignature( jwt, publicKey )
304
+ } else {
305
+ return false;
306
+ }
307
+ }
308
+
309
+ async function _validateJwt( req, customErrorFunction ) {
310
+
311
+ // Get from http header.
312
+ let jwtRaw = req.get( "Authorization" );
313
+
314
+ // Extract jwt from bearer schema.
315
+ let jwt = _extractJwt( jwtRaw, customErrorFunction );
316
+
317
+ // Validate characters string of jwt.
318
+ if ( validate.isJwtString( jwt ) ) {
319
+ return jwt;
320
+ } else {
321
+ throwError( customErrorFunction );
322
+ }
323
+ }
324
+
325
+ async function _validateWebToken( req, headerName, customErrorFunction ) {
326
+
327
+ // Get from http header.
328
+ let jwtRaw = req.get( headerName );
329
+
330
+ // Extract jwt from bearer schema.
331
+ let webToken = _extractWebToken( jwtRaw, customErrorFunction );
332
+
333
+ // Validate characters string of jwt.
334
+ if ( validate.isJwtString( webToken ) ) {
335
+ return webToken;
336
+ } else {
337
+ throwError( customErrorFunction );
338
+ }
339
+ }
340
+
341
+ function _validateJwtNoThrow( req ) {
342
+
343
+ // Get from http header.
344
+ let jwtRaw = req.get( "Authorization" );
345
+
346
+ if ( !jwtRaw ) {
347
+ return null;
348
+ }
349
+
350
+ // Extract jwt from bearer schema.
351
+ let jwt = _extractJwtNoThrow( jwtRaw );
352
+
353
+ // Validate characters string of jwt.
354
+ if ( validate.isJwtString( jwt ) ) {
355
+ return jwt;
356
+ }
357
+
358
+ return null;
359
+ }
360
+
361
+ function _validateWebTokenNoThrow( req, headerName ) {
362
+
363
+ // Get from http header.
364
+ let jwtRaw = req.get( headerName );
365
+
366
+ if ( !jwtRaw ) {
367
+ return null;
368
+ }
369
+
370
+ // Extract jwt from bearer schema.
371
+ let webToken = _extractWebTokenNoThrow( jwtRaw );
372
+
373
+ // Validate characters string of jwt.
374
+ if ( validate.isJwtString( webToken ) ) {
375
+ return webToken;
376
+ }
377
+
378
+ return null;
379
+ }
380
+
381
+ function _validateVisitorNoThrow( req ) {
382
+
383
+ // Get from http header.
384
+ let jwtRaw = req.get( "Visitor" );
385
+
386
+ if ( !jwtRaw ) {
387
+ return null;
388
+ }
389
+
390
+ // Extract jwt from bearer schema.
391
+ let jwt = _extractJwtNoThrow( jwtRaw );
392
+
393
+ // Validate characters string of jwt.
394
+ if ( validate.isJwtString( jwt ) ) {
395
+ return jwt;
396
+ }
397
+
398
+ return null;
399
+ }
400
+
401
+ function _extractJwt( jwtRaw, customErrorFunction ) {
402
+ let jwtSplit = null;
403
+
404
+ if ( jwtRaw && typeof jwtRaw === "string" ) {
405
+ jwtSplit = jwtRaw.split( " " );
406
+ } else {
407
+ throwError( customErrorFunction );
408
+ }
409
+
410
+ if ( jwtSplit[ 0 ]?.toLowerCase() === "bearer" ) {
411
+ return jwtSplit[ 1 ];
412
+ } else {
413
+ throwError( customErrorFunction );
414
+ }
415
+
416
+ return null;
417
+ }
418
+
419
+ function _extractWebToken( jwtRaw, customErrorFunction ) {
420
+
421
+ if ( jwtRaw && typeof jwtRaw === "string" ) {
422
+ return jwtRaw;
423
+ } else {
424
+ throwError( customErrorFunction );
425
+ }
426
+
427
+ return null;
428
+ }
429
+
430
+ function _extractJwtNoThrow( jwtRaw ) {
431
+ let jwtSplit = null;
432
+
433
+ if ( jwtRaw && typeof jwtRaw === "string" ) {
434
+ jwtSplit = jwtRaw.split( " " );
435
+ } else {
436
+ return null;
437
+ }
438
+
439
+ if ( jwtSplit[ 0 ]?.toLowerCase() === "bearer" ) {
440
+ return jwtSplit[ 1 ];
441
+ }
442
+
443
+ return null;
444
+ }
445
+
446
+ function _extractWebTokenNoThrow( jwtRaw ) {
447
+
448
+ if ( jwtRaw && typeof jwtRaw === "string" ) {
449
+ return jwtRaw;
450
+ }
451
+ return null;
452
+ }
453
+
454
+ module.exports = {
455
+ _validateJwt,
456
+ _validateJwtNoThrow,
457
+ _isJwtSignatureValid,
458
+ _isJwtSignatureValidNoThrow,
459
+ _extractJwtObject,
460
+ _extractJwtObjectNoThrow,
461
+ validateAndExtractJwtObject,
462
+ jwtAgeInSeconds,
463
+ isJwtExpired,
464
+ doesJwtUserHasRole,
465
+ jwtClientId,
466
+ visitorClientId,
467
+ verifyJwtAndRole,
468
+ verifyJwt,
469
+ verifyWebTokenNoThrow,
470
+ verifyWebToken,
471
+ verifyJwtNoThrow,
472
+ throwUsedTokenError,
473
+ throwError,
474
+ verifyVisitorNoThrow
475
+ }
@@ -0,0 +1,20 @@
1
+ module.exports = {
2
+ getNameOfRoleFromCode,
3
+ getCodeFromNameOfRole,
4
+ }
5
+
6
+ function getNameOfRoleFromCode( roleCode ) {
7
+ const codesToCategory = {
8
+ "ad": "admin",
9
+ "su": "super_admin",
10
+ }
11
+ return codesToCategory[ roleCode ] || "";
12
+ }
13
+
14
+ function getCodeFromNameOfRole( roleCode ) {
15
+ const codesToCategory = {
16
+ "admin": "ad",
17
+ "super_admin": "su",
18
+ }
19
+ return codesToCategory[ roleCode ] || "";
20
+ }
package/package.json CHANGED
@@ -1,66 +1,28 @@
1
1
  {
2
2
  "name": "@carecard/jwt-read",
3
- "version": "1.0.5",
4
- "private": false,
5
- "description": "Jwt read functions",
6
- "license": "ISC",
7
- "author": "PK Singh",
3
+ "version": "3.0.1",
8
4
  "repository": {
9
5
  "type": "git",
10
- "url": "git+https:github.com/CareCard-ca/pkg-jwt-read.git"
6
+ "url": "https://github.com/CareCard-ca/pkg-jwt-read.git"
7
+ },
8
+ "description": "Jwt read functions",
9
+ "main": "index.js",
10
+ "scripts": {
11
+ "test": "export NODE_ENV=test && mocha --watch --recursive"
11
12
  },
12
13
  "keywords": [
13
14
  "auth",
14
15
  "utility",
15
16
  "cryptology"
16
17
  ],
17
- "type": "module",
18
- "publishConfig": {
19
- "access": "public"
20
- },
21
- "main": "./dist/cjs/index.js",
22
- "module": "./dist/esm/index.js",
23
- "types": "./dist/esm/index.d.ts",
24
- "exports": {
25
- ".": {
26
- "import": "./dist/esm/index.js",
27
- "require": "./dist/cjs/index.js",
28
- "types": "./dist/esm/index.d.ts"
29
- },
30
- "./types": {
31
- "import": "./dist/esm/types.d.ts",
32
- "require": "./dist/cjs/types.d.ts",
33
- "types": "./dist/esm/types.d.ts"
34
- }
35
- },
36
- "files": [
37
- "dist"
38
- ],
39
- "scripts": {
40
- "build": "npm run build:esm && npm run build:cjs",
41
- "build:esm": "tsc -p tsconfig.esm.json",
42
- "build:cjs": "tsc -p tsconfig.cjs.json",
43
- "test": "NODE_NO_WARNINGS=1 jest --coverage",
44
- "format": "prettier --write .",
45
- "format:check": "prettier --check .",
46
- "lint": "eslint",
47
- "prepare": "husky"
48
- },
18
+ "author": "CareCard team",
19
+ "license": "ISC",
49
20
  "devDependencies": {
50
- "@types/express": "5.0.6",
51
- "@types/jest": "30.0.0",
52
- "eslint": "9.39.2",
53
- "husky": "9.1.7",
54
- "jest": "30.2.0",
55
- "prettier": "3.7.4",
56
- "ts-jest": "29.4.6",
57
- "typescript": "5.9.3",
58
- "typescript-eslint": "8.50.1"
21
+ "mocha": "11.7.5"
59
22
  },
60
23
  "dependencies": {
61
- "@carecard/auth-util": "1.0.1",
62
- "@carecard/common-util": "1.0.1",
63
- "@carecard/validate": "1.0.1",
64
- "express": "5.2.1"
24
+ "@carecard/auth-util": "3.0.1",
25
+ "@carecard/common-util": "2.0.2",
26
+ "@carecard/validate": "2.2.12"
65
27
  }
66
28
  }
package/readme.md CHANGED
@@ -7,7 +7,7 @@ This is a collection of jwt reading functions.
7
7
  ### Main functions
8
8
 
9
9
  ```js
10
- const jwtReader = require( '@carecard/jwt-read' );
10
+ const jwtReader = require( '@chatpta/jwt-read' );
11
11
  ```
12
12
 
13
13
  Read jwt
@@ -22,9 +22,11 @@ Following the above ```req.jwt``` contains
22
22
  ```js
23
23
  {
24
24
  header: {
25
- alg: ''
25
+ alg:...
26
26
  }
27
+ ,
27
28
  payload: {
29
+ ...
28
30
  }
29
31
  }
30
32
  ```
@@ -1,3 +0,0 @@
1
- export * from './jwtLib';
2
- export * from './jwtRoles';
3
- export * from './types';
package/dist/cjs/index.js DELETED
@@ -1,19 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./jwtLib"), exports);
18
- __exportStar(require("./jwtRoles"), exports);
19
- __exportStar(require("./types"), exports);
@@ -1,38 +0,0 @@
1
- import type { Response, NextFunction } from 'express';
2
- import { RequestWithJWToken, Role } from './types';
3
- export declare function jwtClientId(req: RequestWithJWToken): string | undefined;
4
- export declare function visitorClientId(req: RequestWithJWToken): string | undefined;
5
- export declare function doesJwtUserHasRole(req: RequestWithJWToken, userRole: Role): boolean | undefined;
6
- export declare function throwError(customErrorFunction?: any): void;
7
- export declare function isJwtExpired(req: RequestWithJWToken, jwtValiditySeconds: number): boolean;
8
- export declare function jwtAgeInMilliseconds(req: RequestWithJWToken): number;
9
- export declare function validateAndExtractJwtObject(req: RequestWithJWToken, publicKey: string, customErrorFunction?: any): Promise<any>;
10
- export declare function validateAndExtractWebToken(req: RequestWithJWToken, publicKey: string, headerName: string, customErrorFunction?: any): Promise<any>;
11
- export declare function validateAndExtractJwtObjectNoThrow(req: RequestWithJWToken, publicKey: string): Promise<any>;
12
- export declare function validateAndExtractWebTokenObjectNoThrow(req: RequestWithJWToken, publicKey: string, headerName: string): Promise<any>;
13
- export declare function validateAndExtractVisitorObjectNoThrow(req: RequestWithJWToken, publicKey: string): Promise<any>;
14
- export declare function verifyJwtAndRole(role: Role, publicKey: string, customErrorFunction?: any): (req: RequestWithJWToken, res: Response, next: NextFunction) => Promise<any>;
15
- export declare function verifyJwt(publicKey: string, customErrorFunction?: any): (req: RequestWithJWToken, res: Response, next: NextFunction) => Promise<any>;
16
- export declare function verifyWebToken(publicKey: string, headerName: string, customErrorFunction?: any): (req: RequestWithJWToken, res: Response, next: NextFunction) => Promise<any>;
17
- export declare function verifyJwtNoThrow(publicKey: string): (req: RequestWithJWToken, res: Response, next: NextFunction) => Promise<void>;
18
- export declare function verifyWebTokenNoThrow(publicKey: string, headerName: string): (req: RequestWithJWToken, res: Response, next: NextFunction) => Promise<void>;
19
- export declare function verifyVisitorNoThrow(publicKey: string): (req: RequestWithJWToken, res: Response, next: NextFunction) => Promise<void>;
20
- export declare function throwUsedTokenError(): void;
21
- /*********************
22
- * Private functions *
23
- *********************/
24
- export declare function _isLoginRequired(hasRequiredRole: boolean | undefined, customErrorFunction?: any): void;
25
- export declare function _extractJwtObject(req: RequestWithJWToken, jwt: string, customErrorFunction?: any): Promise<any>;
26
- export declare function _extractJwtObjectNoThrow(req: RequestWithJWToken, jwt: string): Promise<any>;
27
- export declare function _extractVisitorObjectNoThrow(req: RequestWithJWToken, jwt: string): Promise<any>;
28
- export declare function _isJwtSignatureValid(jwt: string, publicKey: string, customErrorFunction?: any): Promise<any>;
29
- export declare function _isJwtSignatureValidNoThrow(jwt: string | null, publicKey: string): Promise<any>;
30
- export declare function _validateJwt(req: RequestWithJWToken, customErrorFunction?: any): Promise<any>;
31
- export declare function _validateWebToken(req: RequestWithJWToken, headerName: string, customErrorFunction?: any): Promise<any>;
32
- export declare function _validateJwtNoThrow(req: RequestWithJWToken): string | null;
33
- export declare function _validateWebTokenNoThrow(req: RequestWithJWToken, headerName: string): string | null;
34
- export declare function _validateVisitorNoThrow(req: RequestWithJWToken): string | null;
35
- export declare function _extractJwt(jwtRaw: string | undefined, customErrorFunction?: (msg?: string) => never | void): string | null;
36
- export declare function _extractWebToken(jwtRaw: string | undefined, customErrorFunction?: any): string | null;
37
- export declare function _extractJwtNoThrow(jwtRaw: string): string | null;
38
- export declare function _extractWebTokenNoThrow(jwtRaw: string): string | null;