@villedemontreal/jwt-validator 5.10.1 → 5.10.3

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.
@@ -167,6 +167,9 @@ export type CitizenAttributes = CommonUserAttributes & {
167
167
  /**
168
168
  * The attributes of an employee: a user on the payroll of the city of Montreal.
169
169
  *
170
+ * Note that a generic user that has all the required attributes of an employee would be detected as such,
171
+ * for testing purposes.
172
+ *
170
173
  * The ID is mapped to the username.
171
174
  */
172
175
  export type EmployeeAttributes = CommonUserAttributes & {
@@ -210,13 +213,20 @@ export type EmployeeAttributes = CommonUserAttributes & {
210
213
  * The account profile that was selected upon logon.
211
214
  */
212
215
  accountProfile: AccountProfile;
216
+ /**
217
+ * Specifies if the account presented as an external user is a generic account, used for testing purposes.
218
+ */
219
+ isGeneric: boolean;
213
220
  };
214
221
 
215
222
  /**
216
- * The attributes of an external user: a user that is not on the payroll of the city of Montreal but actively collaborates
223
+ * The attributes of an external user: a user that is not on the payroll of the city of Montreal but actively collaborates
217
224
  * with the city and has his own internal email and short code (starting with the letter x).
218
-
219
- * The ID is mapped to the username.
225
+ *
226
+ * Note that a generic user that has all the required attributes of an external user would be detected as such,
227
+ * for testing purposes.
228
+ *
229
+ * The ID is mapped to the username.
220
230
  */
221
231
  export type ExternalUserAttributes = CommonUserAttributes & {
222
232
  type: 'external';
@@ -251,12 +261,20 @@ export type ExternalUserAttributes = CommonUserAttributes & {
251
261
  * The account profile that was selected upon logon.
252
262
  */
253
263
  accountProfile: AccountProfile;
264
+ /**
265
+ * Specifies if the account presented as an external user is a generic account, used for testing purposes.
266
+ */
267
+ isGeneric: boolean;
254
268
  };
255
269
 
256
270
  /**
257
271
  * The attributes of a generic user: a fake user used for testing only, that has the right profile or role to perform specific tasks.
258
-
259
- * The ID is mapped to the username.
272
+ *
273
+ * Note that if a generic user has all the required attributes of an employee or an external user, then it will be detected
274
+ * as such an employee or external user, for testing purposes, and not as a generic user.
275
+ * However, citizens and guest users cannot be generic.
276
+ *
277
+ * The ID is mapped to the username.
260
278
  */
261
279
  export type GenericUserAttributes = CommonUserAttributes & {
262
280
  type: 'generic';
@@ -411,16 +429,20 @@ export type ServiceAccountAttributes =
411
429
  */
412
430
  export type IdentitySource = {
413
431
  /**
414
- * The audience of the JWT, which is usually the clientID our appId.
432
+ * The audience of the JWT, which is usually the clientID of our appId.
415
433
  */
416
434
  aud: string;
417
435
  /**
418
- * Which service issued the JWT that we parsed into an identity.
436
+ * The display name of the audience of the JWT, which is usually the name of our app.
437
+ */
438
+ audDisplayName?: string;
439
+ /**
440
+ * Specifies which service issued the JWT that we parsed into an identity.
419
441
  * Usually, this would be 'security-identity-token-api'.
420
442
  */
421
443
  issuer: string;
422
444
  /**
423
- * Which IDP produced the access token that was submitted to TokenAPI.
445
+ * Specifies which IDP produced the access token that was submitted to TokenAPI.
424
446
  * For EntraID, this would be https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0,
425
447
  * for Azure AD B2C https://connexion.montreal.ca,
426
448
  * for Gluu employee https://idp.montreal.ca,
@@ -429,22 +451,22 @@ export type IdentitySource = {
429
451
  */
430
452
  accessTokenIssuer?: string;
431
453
  /**
432
- * Which claim was used for the unique ID of the identity.
454
+ * Specifies which claim was used for the unique ID of the identity.
433
455
  * This could be: userName, email, mtlIdentityId, aud, sub
434
456
  */
435
457
  claim: string;
436
458
  /**
437
- * The internal ID that would provide access to the user object in the IDP itself.
459
+ * Specifies the internal ID that would provide access to the user object in the IDP itself.
438
460
  * For Azure, this would be the 'oid' (or objectID) and for Gluu this would be the inum (or sub).
439
461
  */
440
462
  internalId: string;
441
463
  /**
442
- * The realm that produced the access token.
464
+ * Specifies the realm that produced the access token.
443
465
  * This could be: employees, citizens, anonymous
444
466
  */
445
467
  realm: string;
446
468
  /**
447
- * The name of the environment that produced the JWT.
469
+ * Specifies the name of the environment that produced the JWT.
448
470
  * This could be: lab, dev, accept, prod
449
471
  */
450
472
  env?: string;
@@ -66,12 +66,14 @@ describe('createIdentityFromJwt', () => {
66
66
  firstName: 'John',
67
67
  lastName: 'DOE',
68
68
  accountProfile: 'vdm',
69
+ isGeneric: false,
69
70
  },
70
71
  source: {
71
72
  issuer: 'security-identity-token-api',
72
73
  accessTokenIssuer:
73
74
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
74
75
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
76
+ audDisplayName: 'infra-auth-auth-playground-dev',
75
77
  env: 'dev',
76
78
  realm: 'employees',
77
79
  claim: 'userName',
@@ -80,7 +82,7 @@ describe('createIdentityFromJwt', () => {
80
82
  });
81
83
  // console.log(JSON.stringify(identity));
82
84
  expect(JSON.stringify(identity)).to.eql(
83
- `{"type":"user","id":"udoejo3","displayName":"John DOE","attributes":{"type":"employee","email":"john.doe@montreal.ca","username":"udoejo3","registrationNumber":"100674051","department":"421408000000","firstName":"John","lastName":"DOE","accountProfile":"vdm"},"source":{"aud":"e5dd632b-cb97-48d7-a310-5147be717cde","issuer":"security-identity-token-api","accessTokenIssuer":"https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0","env":"dev","realm":"employees","claim":"userName","internalId":"0b64042a-9cce-42dc-b645-cd721cbbc179"}}`
85
+ `{"type":"user","id":"udoejo3","displayName":"John DOE","attributes":{"type":"employee","email":"john.doe@montreal.ca","username":"udoejo3","registrationNumber":"100674051","department":"421408000000","firstName":"John","lastName":"DOE","accountProfile":"vdm","isGeneric":false},"source":{"aud":"e5dd632b-cb97-48d7-a310-5147be717cde","audDisplayName":"infra-auth-auth-playground-dev","issuer":"security-identity-token-api","accessTokenIssuer":"https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0","env":"dev","realm":"employees","claim":"userName","internalId":"0b64042a-9cce-42dc-b645-cd721cbbc179"}}`
84
86
  );
85
87
  });
86
88
 
@@ -128,12 +130,14 @@ describe('createIdentityFromJwt', () => {
128
130
  firstName: 'John',
129
131
  lastName: 'DOE',
130
132
  accountProfile: 'spvm',
133
+ isGeneric: false,
131
134
  },
132
135
  source: {
133
136
  issuer: 'security-identity-token-api',
134
137
  accessTokenIssuer:
135
138
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
136
139
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
140
+ audDisplayName: 'infra-auth-auth-playground-dev',
137
141
  env: 'dev',
138
142
  realm: 'employees',
139
143
  claim: 'userName',
@@ -187,12 +191,14 @@ describe('createIdentityFromJwt', () => {
187
191
  firstName: 'John',
188
192
  lastName: 'DOE',
189
193
  accountProfile: 'vdm-admin',
194
+ isGeneric: false,
190
195
  },
191
196
  source: {
192
197
  issuer: 'security-identity-token-api',
193
198
  accessTokenIssuer:
194
199
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
195
200
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
201
+ audDisplayName: 'infra-auth-auth-playground-dev',
196
202
  env: 'dev',
197
203
  realm: 'employees',
198
204
  claim: 'userName',
@@ -245,12 +251,14 @@ describe('createIdentityFromJwt', () => {
245
251
  firstName: 'John',
246
252
  lastName: 'DOE',
247
253
  accountProfile: 'vdm-admin',
254
+ isGeneric: false,
248
255
  },
249
256
  source: {
250
257
  issuer: 'security-identity-token-api',
251
258
  accessTokenIssuer:
252
259
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
253
260
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
261
+ audDisplayName: 'infra-auth-auth-playground-dev',
254
262
  env: 'dev',
255
263
  realm: 'employees',
256
264
  claim: 'userName',
@@ -301,12 +309,14 @@ describe('createIdentityFromJwt', () => {
301
309
  firstName: 'John',
302
310
  lastName: 'DOE',
303
311
  accountProfile: 'vdm',
312
+ isGeneric: false,
304
313
  },
305
314
  source: {
306
315
  issuer: 'security-identity-token-api',
307
316
  accessTokenIssuer:
308
317
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
309
318
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
319
+ audDisplayName: 'infra-auth-auth-playground-dev',
310
320
  env: 'dev',
311
321
  realm: 'employees',
312
322
  claim: 'userName',
@@ -356,12 +366,14 @@ describe('createIdentityFromJwt', () => {
356
366
  firstName: 'John',
357
367
  lastName: 'DOE',
358
368
  accountProfile: 'vdm',
369
+ isGeneric: false,
359
370
  },
360
371
  source: {
361
372
  issuer: 'security-identity-token-api',
362
373
  accessTokenIssuer:
363
374
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
364
375
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
376
+ audDisplayName: 'infra-auth-auth-playground-dev',
365
377
  env: 'dev',
366
378
  realm: 'employees',
367
379
  claim: 'userName',
@@ -417,6 +429,127 @@ describe('createIdentityFromJwt', () => {
417
429
  accessTokenIssuer:
418
430
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
419
431
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
432
+ audDisplayName: 'infra-auth-auth-playground-dev',
433
+ env: 'dev',
434
+ realm: 'employees',
435
+ claim: 'userName',
436
+ internalId: '74096b4e-c090-4a97-af04-bbe25dc4f7d6',
437
+ },
438
+ });
439
+ });
440
+
441
+ it('should recognize a generic user as an employee', () => {
442
+ const jwt: any = {
443
+ iss: 'security-identity-token-api',
444
+ exp: 1722376780,
445
+ iat: 1722371805,
446
+ keyId: 6,
447
+ displayName: 'infra-auth-auth-playground-dev',
448
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
449
+ name: 'C.Generique dsec developpeur2',
450
+ sub: 'mlKfaYaESpCXWGoHE3ej-kCaUBwfsQzqayvRvXXQHJo',
451
+ userName: 'umarba33',
452
+ givenName: 'C.Generique',
453
+ familyName: 'dsec developpeur2',
454
+ email: 'dsec.dev2.test@montreal.ca',
455
+ userType: 'employee',
456
+ department: '4211',
457
+ employeeNumber: '000333',
458
+ oid: '74096b4e-c090-4a97-af04-bbe25dc4f7d6',
459
+ isGenericAccount: true,
460
+ realm: 'employees',
461
+ env: 'dev',
462
+ accessTokenIssuer:
463
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
464
+ };
465
+ const identity = createIdentityFromJwt(jwt);
466
+ // console.log(identity);
467
+
468
+ expect(identity.toString()).to.equal(
469
+ 'user:employee:umarba33:C.Generique dsec developpeur2:dsec.dev2.test@montreal.ca:000333:4211:vdm'
470
+ );
471
+
472
+ delete identity.toString;
473
+ expect(identity).to.eql({
474
+ type: 'user',
475
+ id: 'umarba33',
476
+ displayName: 'C.Generique dsec developpeur2',
477
+ attributes: {
478
+ type: 'employee',
479
+ username: 'umarba33',
480
+ email: 'dsec.dev2.test@montreal.ca',
481
+ registrationNumber: '000333',
482
+ department: '4211',
483
+ firstName: 'C.Generique',
484
+ lastName: 'dsec developpeur2',
485
+ accountProfile: 'vdm',
486
+ isGeneric: true,
487
+ },
488
+ source: {
489
+ issuer: 'security-identity-token-api',
490
+ accessTokenIssuer:
491
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
492
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
493
+ audDisplayName: 'infra-auth-auth-playground-dev',
494
+ env: 'dev',
495
+ realm: 'employees',
496
+ claim: 'userName',
497
+ internalId: '74096b4e-c090-4a97-af04-bbe25dc4f7d6',
498
+ },
499
+ });
500
+ });
501
+
502
+ it('should recognize a generic user as an external user', () => {
503
+ const jwt: any = {
504
+ iss: 'security-identity-token-api',
505
+ exp: 1722376780,
506
+ iat: 1722371805,
507
+ keyId: 6,
508
+ displayName: 'infra-auth-auth-playground-dev',
509
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
510
+ name: 'C.Generique dsec developpeur2',
511
+ sub: 'mlKfaYaESpCXWGoHE3ej-kCaUBwfsQzqayvRvXXQHJo',
512
+ userName: 'xmarba33',
513
+ givenName: 'C.Generique',
514
+ familyName: 'dsec developpeur2',
515
+ email: 'dsec.dev2.test@montreal.ca',
516
+ userType: 'employee',
517
+ department: '4211',
518
+ oid: '74096b4e-c090-4a97-af04-bbe25dc4f7d6',
519
+ isGenericAccount: true,
520
+ realm: 'employees',
521
+ env: 'dev',
522
+ accessTokenIssuer:
523
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
524
+ };
525
+ const identity = createIdentityFromJwt(jwt);
526
+ // console.log(identity);
527
+
528
+ expect(identity.toString()).to.equal(
529
+ 'user:external:xmarba33:C.Generique dsec developpeur2:dsec.dev2.test@montreal.ca:4211:vdm'
530
+ );
531
+
532
+ delete identity.toString;
533
+ expect(identity).to.eql({
534
+ type: 'user',
535
+ id: 'xmarba33',
536
+ displayName: 'C.Generique dsec developpeur2',
537
+ attributes: {
538
+ type: 'external',
539
+ username: 'xmarba33',
540
+ email: 'dsec.dev2.test@montreal.ca',
541
+ department: '4211',
542
+ firstName: 'C.Generique',
543
+ lastName: 'dsec developpeur2',
544
+ accountProfile: 'vdm',
545
+ isGeneric: true,
546
+ },
547
+ source: {
548
+ issuer: 'security-identity-token-api',
549
+ accessTokenIssuer:
550
+ 'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
551
+ aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
552
+ audDisplayName: 'infra-auth-auth-playground-dev',
420
553
  env: 'dev',
421
554
  realm: 'employees',
422
555
  claim: 'userName',
@@ -470,6 +603,7 @@ describe('createIdentityFromJwt', () => {
470
603
  accessTokenIssuer:
471
604
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
472
605
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
606
+ audDisplayName: 'infra-auth-auth-playground-dev',
473
607
  env: 'dev',
474
608
  realm: 'employees',
475
609
  claim: 'userName',
@@ -515,6 +649,7 @@ describe('createIdentityFromJwt', () => {
515
649
  issuer: 'security-identity-token-api',
516
650
  accessTokenIssuer: 'security-identity-anonymous-token-api',
517
651
  aud: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0008!2212.0010',
652
+ audDisplayName: 'Account Identity Managment',
518
653
  env: 'dev',
519
654
  realm: 'anonymous',
520
655
  claim: 'userName',
@@ -559,6 +694,7 @@ describe('createIdentityFromJwt', () => {
559
694
  accessTokenIssuer:
560
695
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
561
696
  aud: 'e5dd632b-cb97-48d7-a310-cde5147be717',
697
+ audDisplayName: 'infra-auth-auth-playground-dev',
562
698
  env: 'dev',
563
699
  realm: 'employees',
564
700
  claim: 'aud',
@@ -606,6 +742,7 @@ describe('createIdentityFromJwt', () => {
606
742
  issuer: 'security-identity-token-api',
607
743
  accessTokenIssuer: 'https://auth.dev.interne.montreal.ca',
608
744
  aud: '@!4025.CA62.9BB6.16C5!0001!2212.0010!0008!2212.0130',
745
+ audDisplayName: 'DiagnosticsCanary',
609
746
  env: 'dev',
610
747
  realm: 'citizens',
611
748
  claim: 'userName',
@@ -660,6 +797,7 @@ describe('createIdentityFromJwt', () => {
660
797
  accessTokenIssuer:
661
798
  'https://connexion.dev.montreal.ca/1543b575-116b-4325-a0bf-3ccdd7925321/v2.0/',
662
799
  aud: 'a496befa-db7d-45a6-ac7a-11471816b8f1',
800
+ audDisplayName: 'infra-auth-auth-playground',
663
801
  env: 'dev',
664
802
  realm: 'citizens',
665
803
  claim: 'mtlIdentityId',
@@ -715,6 +853,7 @@ describe('createIdentityFromJwt', () => {
715
853
  accessTokenIssuer:
716
854
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
717
855
  aud: 'a496befa-db7d-45a6-ac7a-11471816b8f1',
856
+ audDisplayName: 'infra-auth-auth-playground',
718
857
  env: 'dev',
719
858
  realm: 'employees',
720
859
  claim: 'userName',
@@ -757,6 +896,7 @@ describe('createIdentityFromJwt', () => {
757
896
  accessTokenIssuer:
758
897
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
759
898
  aud: 'a496befa-db7d-45a6-ac7a-11471816b8f1',
899
+ audDisplayName: 'infra-auth-auth-playground',
760
900
  env: 'dev',
761
901
  realm: 'employees',
762
902
  claim: 'sub',
@@ -799,6 +939,7 @@ describe('createIdentityFromJwt', () => {
799
939
  accessTokenIssuer:
800
940
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
801
941
  aud: 'a496befa-db7d-45a6-ac7a-11471816b8f1',
942
+ audDisplayName: 'infra-auth-auth-playground',
802
943
  env: 'dev',
803
944
  realm: 'employees',
804
945
  claim: 'sub',
@@ -858,6 +999,7 @@ describe('createIdentityFromJwt', () => {
858
999
  accessTokenIssuer:
859
1000
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
860
1001
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1002
+ audDisplayName: 'infra-auth-auth-playground-dev',
861
1003
  env: 'dev',
862
1004
  realm: 'employees',
863
1005
  claim: 'userName',
@@ -917,6 +1059,7 @@ describe('createIdentityFromJwt', () => {
917
1059
  accessTokenIssuer:
918
1060
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
919
1061
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1062
+ audDisplayName: 'infra-auth-auth-playground-dev',
920
1063
  env: 'dev',
921
1064
  realm: 'employees',
922
1065
  claim: 'userName',
@@ -976,6 +1119,7 @@ describe('createIdentityFromJwt', () => {
976
1119
  accessTokenIssuer:
977
1120
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
978
1121
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1122
+ audDisplayName: 'infra-auth-auth-playground-dev',
979
1123
  env: 'dev',
980
1124
  realm: 'employees',
981
1125
  claim: 'userName',
@@ -1034,6 +1178,7 @@ describe('createIdentityFromJwt', () => {
1034
1178
  accessTokenIssuer:
1035
1179
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1036
1180
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1181
+ audDisplayName: 'infra-auth-auth-playground-dev',
1037
1182
  env: 'dev',
1038
1183
  realm: 'employees',
1039
1184
  claim: 'email',
@@ -1092,6 +1237,7 @@ describe('createIdentityFromJwt', () => {
1092
1237
  accessTokenIssuer:
1093
1238
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1094
1239
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1240
+ audDisplayName: 'infra-auth-auth-playground-dev',
1095
1241
  env: 'dev',
1096
1242
  realm: 'employees',
1097
1243
  claim: 'userName',
@@ -1150,6 +1296,7 @@ describe('createIdentityFromJwt', () => {
1150
1296
  accessTokenIssuer:
1151
1297
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1152
1298
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1299
+ audDisplayName: 'infra-auth-auth-playground-dev',
1153
1300
  env: 'dev',
1154
1301
  realm: 'employees',
1155
1302
  claim: 'userName',
@@ -1208,6 +1355,7 @@ describe('createIdentityFromJwt', () => {
1208
1355
  accessTokenIssuer:
1209
1356
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1210
1357
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1358
+ audDisplayName: 'infra-auth-auth-playground-dev',
1211
1359
  env: 'dev',
1212
1360
  realm: 'employees',
1213
1361
  claim: 'userName',
@@ -1266,6 +1414,7 @@ describe('createIdentityFromJwt', () => {
1266
1414
  accessTokenIssuer:
1267
1415
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1268
1416
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1417
+ audDisplayName: 'infra-auth-auth-playground-dev',
1269
1418
  env: 'dev',
1270
1419
  realm: 'employees',
1271
1420
  claim: 'userName',
@@ -1325,6 +1474,7 @@ describe('createIdentityFromJwt', () => {
1325
1474
  accessTokenIssuer:
1326
1475
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1327
1476
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1477
+ audDisplayName: 'infra-auth-auth-playground-dev',
1328
1478
  env: 'dev',
1329
1479
  realm: 'employees',
1330
1480
  claim: 'userName',
@@ -1381,6 +1531,7 @@ describe('createIdentityFromJwt', () => {
1381
1531
  accessTokenIssuer:
1382
1532
  'https://login.microsoftonline.com/9f15d2dc-8753-4f83-aac2-a58288d3a4bc/v2.0',
1383
1533
  aud: 'e5dd632b-cb97-48d7-a310-5147be717cde',
1534
+ audDisplayName: 'infra-auth-auth-playground-dev',
1384
1535
  env: 'dev',
1385
1536
  realm: 'employees',
1386
1537
  claim: 'userName',
@@ -60,11 +60,12 @@ export function createIdentityFromJwt(jwt: any): Identity {
60
60
  const realm = getStringClaim(jwt, 'realm');
61
61
  const aud = getStringClaim(jwt, 'aud');
62
62
  const sub = getStringClaim(jwt, 'sub');
63
+ const audDisplayName = getOptionalStringClaim(jwt, 'displayName');
63
64
  const oid = getOptionalStringClaim(jwt, 'oid');
64
65
  const env = getOptionalStringClaim(jwt, 'env');
65
66
  const userType = getOptionalStringClaim(jwt, 'userType') ?? 'citizen';
66
67
  const accessTokenIssuer = getOptionalStringClaim(jwt, 'accessTokenIssuer');
67
- const isGenericUser = jwt.isGenericAccount;
68
+ const isGenericUser = jwt.isGenericAccount === true;
68
69
 
69
70
  //----------< Anonymous user >-----------------------------------------
70
71
  if (userType === 'anonymous') {
@@ -83,6 +84,7 @@ export function createIdentityFromJwt(jwt: any): Identity {
83
84
  },
84
85
  source: {
85
86
  aud,
87
+ audDisplayName,
86
88
  issuer,
87
89
  accessTokenIssuer,
88
90
  env,
@@ -109,6 +111,7 @@ export function createIdentityFromJwt(jwt: any): Identity {
109
111
  },
110
112
  source: {
111
113
  aud,
114
+ audDisplayName,
112
115
  issuer,
113
116
  accessTokenIssuer,
114
117
  env,
@@ -137,6 +140,7 @@ export function createIdentityFromJwt(jwt: any): Identity {
137
140
  },
138
141
  source: {
139
142
  aud,
143
+ audDisplayName,
140
144
  issuer,
141
145
  accessTokenIssuer,
142
146
  env,
@@ -170,6 +174,7 @@ export function createIdentityFromJwt(jwt: any): Identity {
170
174
  },
171
175
  source: {
172
176
  aud,
177
+ audDisplayName,
173
178
  issuer,
174
179
  accessTokenIssuer,
175
180
  env,
@@ -189,47 +194,6 @@ export function createIdentityFromJwt(jwt: any): Identity {
189
194
  };
190
195
  return result;
191
196
  }
192
- //----------< Generic user >-----------------------------------------
193
- if (isGenericUser === true) {
194
- const type = 'user';
195
- const subType = 'generic-user';
196
- const username = getStringClaim(jwt, usernameClaimName, type, subType);
197
- const result: GenericUserIdentity = {
198
- type,
199
- id: username,
200
- displayName: getStringClaim(jwt, 'name', type, subType),
201
- attributes: {
202
- type: 'generic',
203
- username,
204
- email: getOptionalStringClaim(jwt, 'email'),
205
- department: getOptionalStringClaim(jwt, 'department'),
206
- firstName: getStringClaim(jwt, 'givenName', type, subType),
207
- lastName: getStringClaim(jwt, 'familyName', type, subType),
208
- accountProfile: getAccountProfile(jwt),
209
- },
210
- source: {
211
- aud,
212
- issuer,
213
- accessTokenIssuer,
214
- env,
215
- realm,
216
- claim: usernameClaimName,
217
- internalId: oid ?? sub,
218
- },
219
- toString(this: GenericUserIdentity) {
220
- return encodeComponents(
221
- this.type,
222
- this.attributes.type,
223
- this.id,
224
- this.displayName,
225
- this.attributes.email,
226
- this.attributes.department,
227
- this.attributes.accountProfile
228
- );
229
- },
230
- };
231
- return result;
232
- }
233
197
  //----------< Employee >-----------------------------------------
234
198
  if (userType === 'employee' && isEmployee(jwt)) {
235
199
  const type = 'user';
@@ -251,9 +215,11 @@ export function createIdentityFromJwt(jwt: any): Identity {
251
215
  firstName: getStringClaim(jwt, 'givenName', type, subType),
252
216
  lastName: getStringClaim(jwt, 'familyName', type, subType),
253
217
  accountProfile: getAccountProfile(jwt),
218
+ isGeneric: isGenericUser,
254
219
  },
255
220
  source: {
256
221
  aud,
222
+ audDisplayName,
257
223
  issuer,
258
224
  accessTokenIssuer,
259
225
  env,
@@ -296,9 +262,11 @@ export function createIdentityFromJwt(jwt: any): Identity {
296
262
  firstName: getStringClaim(jwt, 'givenName', type, subType),
297
263
  lastName: getStringClaim(jwt, 'familyName', type, subType),
298
264
  accountProfile: getAccountProfile(jwt),
265
+ isGeneric: isGenericUser,
299
266
  },
300
267
  source: {
301
268
  aud,
269
+ audDisplayName,
302
270
  issuer,
303
271
  accessTokenIssuer,
304
272
  env,
@@ -340,6 +308,7 @@ export function createIdentityFromJwt(jwt: any): Identity {
340
308
  },
341
309
  source: {
342
310
  aud,
311
+ audDisplayName,
343
312
  issuer,
344
313
  accessTokenIssuer,
345
314
  env,
@@ -360,6 +329,48 @@ export function createIdentityFromJwt(jwt: any): Identity {
360
329
  };
361
330
  return result;
362
331
  }
332
+ //----------< Generic user >-----------------------------------------
333
+ if (isGenericUser) {
334
+ const type = 'user';
335
+ const subType = 'generic-user';
336
+ const username = getStringClaim(jwt, usernameClaimName, type, subType);
337
+ const result: GenericUserIdentity = {
338
+ type,
339
+ id: username,
340
+ displayName: getStringClaim(jwt, 'name', type, subType),
341
+ attributes: {
342
+ type: 'generic',
343
+ username,
344
+ email: getOptionalStringClaim(jwt, 'email'),
345
+ department: getOptionalStringClaim(jwt, 'department'),
346
+ firstName: getStringClaim(jwt, 'givenName', type, subType),
347
+ lastName: getStringClaim(jwt, 'familyName', type, subType),
348
+ accountProfile: getAccountProfile(jwt),
349
+ },
350
+ source: {
351
+ aud,
352
+ audDisplayName,
353
+ issuer,
354
+ accessTokenIssuer,
355
+ env,
356
+ realm,
357
+ claim: usernameClaimName,
358
+ internalId: oid ?? sub,
359
+ },
360
+ toString(this: GenericUserIdentity) {
361
+ return encodeComponents(
362
+ this.type,
363
+ this.attributes.type,
364
+ this.id,
365
+ this.displayName,
366
+ this.attributes.email,
367
+ this.attributes.department,
368
+ this.attributes.accountProfile
369
+ );
370
+ },
371
+ };
372
+ return result;
373
+ }
363
374
  //----------< Unknown user type >-----------------------------------------
364
375
  const username = getOptionalStringClaim(jwt, usernameClaimName);
365
376
  const email = getOptionalStringClaim(jwt, 'email');
@@ -383,6 +394,7 @@ export function createIdentityFromJwt(jwt: any): Identity {
383
394
  },
384
395
  source: {
385
396
  aud,
397
+ audDisplayName,
386
398
  issuer,
387
399
  accessTokenIssuer,
388
400
  env,
@@ -415,6 +427,7 @@ export function createIdentityFromJwt(jwt: any): Identity {
415
427
  },
416
428
  source: {
417
429
  aud,
430
+ audDisplayName,
418
431
  issuer,
419
432
  accessTokenIssuer,
420
433
  env,