@carecard/jwt-read 3.1.17 → 3.1.27

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.d.ts CHANGED
@@ -40,6 +40,22 @@ export interface JwtPayload {
40
40
  [key: string]: any;
41
41
  }
42
42
 
43
+ /**
44
+ * Represents the compact authorization-context JWT claims issued for scoped resource access.
45
+ */
46
+ export interface UserAuthorizationPayload extends JwtPayload {
47
+ typ?: string;
48
+ iss?: string;
49
+ aud?: string | string[];
50
+ schema?: string;
51
+ table?: string;
52
+ actions?: string[];
53
+ scopeType?: string;
54
+ scopeId?: string | null;
55
+ authzVersion?: string;
56
+ jti?: string;
57
+ }
58
+
43
59
  /**
44
60
  * Container for the decoded header and payload of a JWT.
45
61
  */
@@ -73,11 +89,33 @@ export interface VisitorRequestObject {
73
89
  }
74
90
 
75
91
  /**
76
- * Extended Express Request to include jwt and visitor objects.
92
+ * Structure of the scoped authorization object attached to the request.
93
+ */
94
+ export interface UserAuthorizationRequestObject {
95
+ header: JwtHeader;
96
+ payload: UserAuthorizationPayload;
97
+ }
98
+
99
+ export interface UserAuthorizationTokenOptions {
100
+ publicKey?: string;
101
+ headerName?: string;
102
+ maxTokenLength?: number;
103
+ expectedType?: string;
104
+ expectedIssuer?: string;
105
+ expectedAudience?: string | string[];
106
+ }
107
+
108
+ export interface UserAuthorizationReadOptions {
109
+ userAuthorization?: UserAuthorizationTokenOptions;
110
+ }
111
+
112
+ /**
113
+ * Extended Express Request to include jwt, visitor, and userAuthorization objects.
77
114
  */
78
115
  export interface AuthenticatedRequest extends Request {
79
116
  jwt?: JwtRequestObject | null;
80
117
  visitor?: VisitorRequestObject | null;
118
+ userAuthorization?: UserAuthorizationRequestObject | null;
81
119
  }
82
120
 
83
121
  export interface ServerAuthIntrospectionClaims {
@@ -111,6 +149,7 @@ export type ServerAuthIntrospector = (
111
149
  export function jwtVerify(
112
150
  publicKey: string,
113
151
  customErrorFunction?: () => void,
152
+ options?: UserAuthorizationReadOptions,
114
153
  ): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
115
154
 
116
155
  /**
@@ -121,13 +160,17 @@ export function jwtVerifyWebToken(
121
160
  publicKey: string,
122
161
  headerName: string,
123
162
  customErrorFunction?: () => void,
163
+ options?: UserAuthorizationReadOptions,
124
164
  ): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
125
165
 
126
166
  /**
127
167
  * Returns a middleware that verifies a JWT from the 'Authorization: Bearer <token>' header
128
168
  * and extracts it into req.jwt. Returns false instead of throwing if invalid.
129
169
  */
130
- export function jwtVerifyNoThrow(publicKey: string): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
170
+ export function jwtVerifyNoThrow(
171
+ publicKey: string,
172
+ options?: UserAuthorizationReadOptions,
173
+ ): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
131
174
 
132
175
  /**
133
176
  * Returns a middleware that verifies a JWT from a custom header and extracts it into req.jwt.
@@ -136,13 +179,34 @@ export function jwtVerifyNoThrow(publicKey: string): (req: AuthenticatedRequest,
136
179
  export function jwtVerifyWebTokenNoThrow(
137
180
  publicKey: string,
138
181
  headerName: string,
182
+ options?: UserAuthorizationReadOptions,
183
+ ): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
184
+
185
+ /**
186
+ * Returns middleware that verifies X-Authorization-Context and extracts it into req.userAuthorization.
187
+ */
188
+ export function jwtVerifyUserAuthorization(
189
+ publicKey: string,
190
+ customErrorFunction?: () => void,
191
+ options?: UserAuthorizationTokenOptions,
192
+ ): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
193
+
194
+ /**
195
+ * Returns middleware that verifies X-Authorization-Context into req.userAuthorization without throwing for invalid tokens.
196
+ */
197
+ export function jwtVerifyUserAuthorizationNoThrow(
198
+ publicKey: string,
199
+ options?: UserAuthorizationTokenOptions,
139
200
  ): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
140
201
 
141
202
  /**
142
203
  * Returns a middleware that verifies a visitor token from the 'Visitor' header
143
204
  * and extracts it into req.visitor. Returns false instead of throwing if invalid.
144
205
  */
145
- export function jwtVerifyVisitorNoThrow(publicKey: string): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
206
+ export function jwtVerifyVisitorNoThrow(
207
+ publicKey: string,
208
+ options?: UserAuthorizationReadOptions,
209
+ ): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
146
210
 
147
211
  /**
148
212
  * Returns the sub from the extracted JWT in req.jwt.
@@ -173,6 +237,7 @@ export function jwtVerifyAndHasRole(
173
237
  userRole: string,
174
238
  publicKey: string,
175
239
  customErrorFunction?: () => void,
240
+ options?: UserAuthorizationReadOptions,
176
241
  ): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
177
242
 
178
243
  /**
@@ -183,6 +248,7 @@ export function jwtVerifyOrServerAuth(
183
248
  publicKey: string,
184
249
  serverAuthIntrospector: ServerAuthIntrospector,
185
250
  customErrorFunction?: () => void,
251
+ options?: UserAuthorizationReadOptions,
186
252
  ): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
187
253
 
188
254
  /**
@@ -194,6 +260,7 @@ export function jwtVerifyOrServerAuthAndHasRole(
194
260
  publicKey: string,
195
261
  serverAuthIntrospector: ServerAuthIntrospector,
196
262
  customErrorFunction?: () => void,
263
+ options?: UserAuthorizationReadOptions,
197
264
  ): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
198
265
 
199
266
  /**
@@ -225,7 +292,31 @@ export function jwtGetContext(req: any): JwtContext;
225
292
  /**
226
293
  * Validates the JWT from the Authorization header and extracts it into req.jwt.
227
294
  */
228
- export function jwtValidateAndExtract(req: AuthenticatedRequest, publicKey: string, customErrorFunction?: () => void): void;
295
+ export function jwtValidateAndExtract(
296
+ req: AuthenticatedRequest,
297
+ publicKey: string,
298
+ customErrorFunction?: () => void,
299
+ options?: UserAuthorizationReadOptions,
300
+ ): void;
301
+
302
+ /**
303
+ * Validates X-Authorization-Context and extracts it into req.userAuthorization.
304
+ */
305
+ export function jwtValidateAndExtractUserAuthorization(
306
+ req: AuthenticatedRequest,
307
+ publicKey: string,
308
+ customErrorFunction?: () => void,
309
+ options?: UserAuthorizationTokenOptions,
310
+ ): void;
311
+
312
+ /**
313
+ * Validates X-Authorization-Context and extracts it into req.userAuthorization (no-throw).
314
+ */
315
+ export function jwtValidateAndExtractUserAuthorizationNoThrow(
316
+ req: AuthenticatedRequest,
317
+ publicKey: string,
318
+ options?: UserAuthorizationTokenOptions,
319
+ ): void;
229
320
 
230
321
  /**
231
322
  * Validates a service-to-service JWT from the Authorization header and extracts it into req.jwt.
@@ -236,6 +327,7 @@ export function jwtValidateAndExtractService(
236
327
  expectedIssuer: string,
237
328
  expectedAudience: string,
238
329
  customErrorFunction?: () => void,
330
+ options?: UserAuthorizationReadOptions,
239
331
  ): void;
240
332
 
241
333
  /**
@@ -247,6 +339,7 @@ export function jwtValidateAndExtractOrServerAuth(
247
339
  publicKey: string,
248
340
  serverAuthIntrospector: ServerAuthIntrospector,
249
341
  customErrorFunction?: () => void,
342
+ options?: UserAuthorizationReadOptions,
250
343
  ): Promise<void>;
251
344
 
252
345
  /**
@@ -257,22 +350,32 @@ export function jwtValidateAndExtractWebToken(
257
350
  publicKey: string,
258
351
  headerName: string,
259
352
  customErrorFunction?: () => void,
353
+ options?: UserAuthorizationReadOptions,
260
354
  ): void;
261
355
 
262
356
  /**
263
357
  * Validates the JWT from the Authorization header and extracts it into req.jwt (no-throw).
264
358
  */
265
- export function jwtValidateAndExtractNoThrow(req: AuthenticatedRequest, publicKey: string): void;
359
+ export function jwtValidateAndExtractNoThrow(req: AuthenticatedRequest, publicKey: string, options?: UserAuthorizationReadOptions): void;
266
360
 
267
361
  /**
268
362
  * Validates the JWT from a custom header and extracts it into req.jwt (no-throw).
269
363
  */
270
- export function jwtValidateAndExtractWebTokenNoThrow(req: AuthenticatedRequest, publicKey: string, headerName: string): void;
364
+ export function jwtValidateAndExtractWebTokenNoThrow(
365
+ req: AuthenticatedRequest,
366
+ publicKey: string,
367
+ headerName: string,
368
+ options?: UserAuthorizationReadOptions,
369
+ ): void;
271
370
 
272
371
  /**
273
372
  * Validates the visitor token from the 'Visitor' header and extracts it into req.visitor (no-throw).
274
373
  */
275
- export function jwtValidateAndExtractVisitorNoThrow(req: AuthenticatedRequest, publicKey: string): void;
374
+ export function jwtValidateAndExtractVisitorNoThrow(
375
+ req: AuthenticatedRequest,
376
+ publicKey: string,
377
+ options?: UserAuthorizationReadOptions,
378
+ ): void;
276
379
 
277
380
  /**
278
381
  * Returns middleware that verifies a service-to-service JWT from one expected sender.
@@ -282,6 +385,7 @@ export function jwtVerifyService(
282
385
  expectedIssuer: string,
283
386
  expectedAudience: string,
284
387
  customErrorFunction?: () => void,
388
+ options?: UserAuthorizationReadOptions,
285
389
  ): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
286
390
 
287
391
  /**
@@ -292,6 +396,7 @@ export function jwtVerifyService(
292
396
  export function verifyJwt(
293
397
  publicKey: string,
294
398
  customErrorFunction?: () => void,
399
+ options?: UserAuthorizationReadOptions,
295
400
  ): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
296
401
 
297
402
  /**
@@ -303,6 +408,7 @@ export function verifyWebToken(
303
408
  publicKey: string,
304
409
  headerName: string,
305
410
  customErrorFunction?: () => void,
411
+ options?: UserAuthorizationReadOptions,
306
412
  ): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
307
413
 
308
414
  /**
@@ -310,7 +416,10 @@ export function verifyWebToken(
310
416
  * and extracts it into req.jwt. Returns false instead of throwing if invalid.
311
417
  * @deprecated use jwtVerifyNoThrow
312
418
  */
313
- export function verifyJwtNoThrow(publicKey: string): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
419
+ export function verifyJwtNoThrow(
420
+ publicKey: string,
421
+ options?: UserAuthorizationReadOptions,
422
+ ): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
314
423
 
315
424
  /**
316
425
  * Returns a middleware that verifies a JWT from a custom header and extracts it into req.jwt.
@@ -320,6 +429,7 @@ export function verifyJwtNoThrow(publicKey: string): (req: AuthenticatedRequest,
320
429
  export function verifyWebTokenNoThrow(
321
430
  publicKey: string,
322
431
  headerName: string,
432
+ options?: UserAuthorizationReadOptions,
323
433
  ): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
324
434
 
325
435
  /**
@@ -327,7 +437,10 @@ export function verifyWebTokenNoThrow(
327
437
  * and extracts it into req.visitor. Returns false instead of throwing if invalid.
328
438
  * @deprecated use jwtVerifyVisitorNoThrow
329
439
  */
330
- export function verifyVisitorNoThrow(publicKey: string): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
440
+ export function verifyVisitorNoThrow(
441
+ publicKey: string,
442
+ options?: UserAuthorizationReadOptions,
443
+ ): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
331
444
 
332
445
  /**
333
446
  * Returns the sub from the extracted JWT in req.jwt.
@@ -365,6 +478,7 @@ export function verifyJwtAndRole(
365
478
  userRole: string,
366
479
  publicKey: string,
367
480
  customErrorFunction?: () => void,
481
+ options?: UserAuthorizationReadOptions,
368
482
  ): (req: AuthenticatedRequest, res: Response, next: NextFunction) => void;
369
483
 
370
484
  /**
package/index.js CHANGED
@@ -6,6 +6,8 @@ module.exports = {
6
6
  jwtVerifyWebToken: jwtLib.verifyWebToken,
7
7
  jwtVerifyNoThrow: jwtLib.verifyJwtNoThrow,
8
8
  jwtVerifyWebTokenNoThrow: jwtLib.verifyWebTokenNoThrow,
9
+ jwtVerifyUserAuthorization: jwtLib.verifyUserAuthorization,
10
+ jwtVerifyUserAuthorizationNoThrow: jwtLib.verifyUserAuthorizationNoThrow,
9
11
  jwtVerifyVisitorNoThrow: jwtLib.verifyVisitorNoThrow,
10
12
  jwtGetClientId: jwtLib.jwtClientId,
11
13
  jwtGetVisitorClientId: jwtLib.visitorClientId,
@@ -16,6 +18,8 @@ module.exports = {
16
18
  jwtGetRoleCode: jwtRoles.getCodeFromNameOfRole,
17
19
  jwtGetContext: jwtRoles.getContext,
18
20
  jwtValidateAndExtract: jwtLib.validateAndExtractJwtObject,
21
+ jwtValidateAndExtractUserAuthorization: jwtLib.validateAndExtractUserAuthorizationObject,
22
+ jwtValidateAndExtractUserAuthorizationNoThrow: jwtLib.validateAndExtractUserAuthorizationObjectNoThrow,
19
23
  jwtValidateAndExtractService: jwtLib.validateAndExtractServiceJwtObject,
20
24
  jwtValidateAndExtractOrServerAuth: jwtLib.validateAndExtractJwtOrServerAuthObject,
21
25
  jwtValidateAndExtractWebToken: jwtLib.validateAndExtractWebToken,