@azure/msal-common 14.1.0 → 14.3.0

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.
Files changed (149) hide show
  1. package/dist/account/AuthToken.mjs +1 -1
  2. package/dist/account/CcsCredential.mjs +1 -1
  3. package/dist/account/ClientInfo.mjs +1 -1
  4. package/dist/authority/Authority.d.ts +25 -11
  5. package/dist/authority/Authority.d.ts.map +1 -1
  6. package/dist/authority/Authority.mjs +122 -71
  7. package/dist/authority/Authority.mjs.map +1 -1
  8. package/dist/authority/AuthorityFactory.d.ts.map +1 -1
  9. package/dist/authority/AuthorityFactory.mjs +3 -3
  10. package/dist/authority/AuthorityMetadata.d.ts +42 -162
  11. package/dist/authority/AuthorityMetadata.d.ts.map +1 -1
  12. package/dist/authority/AuthorityMetadata.mjs +106 -384
  13. package/dist/authority/AuthorityMetadata.mjs.map +1 -1
  14. package/dist/authority/AuthorityOptions.d.ts +6 -0
  15. package/dist/authority/AuthorityOptions.d.ts.map +1 -1
  16. package/dist/authority/AuthorityOptions.mjs +1 -1
  17. package/dist/authority/AuthorityOptions.mjs.map +1 -1
  18. package/dist/authority/AuthorityType.mjs +1 -1
  19. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
  20. package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
  21. package/dist/authority/OpenIdConfigResponse.mjs +1 -1
  22. package/dist/authority/ProtocolMode.mjs +1 -1
  23. package/dist/authority/RegionDiscovery.mjs +1 -1
  24. package/dist/cache/CacheManager.d.ts +17 -1
  25. package/dist/cache/CacheManager.d.ts.map +1 -1
  26. package/dist/cache/CacheManager.mjs +79 -37
  27. package/dist/cache/CacheManager.mjs.map +1 -1
  28. package/dist/cache/entities/AccessTokenEntity.d.ts +12 -43
  29. package/dist/cache/entities/AccessTokenEntity.d.ts.map +1 -1
  30. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  31. package/dist/cache/entities/AccountEntity.mjs +1 -3
  32. package/dist/cache/entities/AccountEntity.mjs.map +1 -1
  33. package/dist/cache/entities/AppMetadataEntity.mjs +1 -1
  34. package/dist/cache/entities/AuthorityMetadataEntity.mjs +1 -1
  35. package/dist/cache/entities/CacheRecord.mjs +1 -1
  36. package/dist/cache/entities/CredentialEntity.d.ts +15 -73
  37. package/dist/cache/entities/CredentialEntity.d.ts.map +1 -1
  38. package/dist/cache/entities/IdTokenEntity.d.ts +4 -30
  39. package/dist/cache/entities/IdTokenEntity.d.ts.map +1 -1
  40. package/dist/cache/entities/RefreshTokenEntity.d.ts +2 -33
  41. package/dist/cache/entities/RefreshTokenEntity.d.ts.map +1 -1
  42. package/dist/cache/entities/ServerTelemetryEntity.mjs +1 -1
  43. package/dist/cache/entities/ThrottlingEntity.mjs +1 -1
  44. package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
  45. package/dist/cache/utils/CacheHelpers.d.ts +59 -0
  46. package/dist/cache/utils/CacheHelpers.d.ts.map +1 -0
  47. package/dist/cache/utils/CacheHelpers.mjs +226 -0
  48. package/dist/cache/utils/CacheHelpers.mjs.map +1 -0
  49. package/dist/cache/utils/CacheTypes.d.ts +1 -0
  50. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  51. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  52. package/dist/client/AuthorizationCodeClient.mjs +3 -3
  53. package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
  54. package/dist/client/BaseClient.d.ts +2 -2
  55. package/dist/client/BaseClient.d.ts.map +1 -1
  56. package/dist/client/BaseClient.mjs +11 -10
  57. package/dist/client/BaseClient.mjs.map +1 -1
  58. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  59. package/dist/client/RefreshTokenClient.mjs +4 -4
  60. package/dist/client/RefreshTokenClient.mjs.map +1 -1
  61. package/dist/client/SilentFlowClient.d.ts +1 -0
  62. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  63. package/dist/client/SilentFlowClient.mjs +20 -27
  64. package/dist/client/SilentFlowClient.mjs.map +1 -1
  65. package/dist/config/ClientConfiguration.mjs +1 -1
  66. package/dist/crypto/ICrypto.mjs +1 -1
  67. package/dist/crypto/JoseHeader.mjs +1 -1
  68. package/dist/crypto/PopTokenGenerator.mjs +1 -1
  69. package/dist/error/AuthError.mjs +1 -1
  70. package/dist/error/AuthErrorCodes.mjs +1 -1
  71. package/dist/error/ClientAuthError.d.ts +5 -0
  72. package/dist/error/ClientAuthError.d.ts.map +1 -1
  73. package/dist/error/ClientAuthError.mjs +7 -2
  74. package/dist/error/ClientAuthError.mjs.map +1 -1
  75. package/dist/error/ClientAuthErrorCodes.d.ts +1 -0
  76. package/dist/error/ClientAuthErrorCodes.d.ts.map +1 -1
  77. package/dist/error/ClientAuthErrorCodes.mjs +3 -2
  78. package/dist/error/ClientAuthErrorCodes.mjs.map +1 -1
  79. package/dist/error/ClientConfigurationError.mjs +1 -1
  80. package/dist/error/ClientConfigurationErrorCodes.mjs +1 -1
  81. package/dist/error/InteractionRequiredAuthError.mjs +1 -1
  82. package/dist/error/InteractionRequiredAuthErrorCodes.mjs +1 -1
  83. package/dist/error/JoseHeaderError.mjs +1 -1
  84. package/dist/error/JoseHeaderErrorCodes.mjs +1 -1
  85. package/dist/error/ServerError.mjs +1 -1
  86. package/dist/index.cjs +5157 -5476
  87. package/dist/index.cjs.map +1 -1
  88. package/dist/index.d.ts +3 -2
  89. package/dist/index.d.ts.map +1 -1
  90. package/dist/index.mjs +4 -6
  91. package/dist/index.mjs.map +1 -1
  92. package/dist/logger/Logger.mjs +1 -1
  93. package/dist/network/INetworkModule.mjs +1 -1
  94. package/dist/network/NetworkManager.mjs +1 -1
  95. package/dist/network/ThrottlingUtils.mjs +1 -1
  96. package/dist/packageMetadata.d.ts +1 -1
  97. package/dist/packageMetadata.mjs +2 -2
  98. package/dist/request/AuthenticationHeaderParser.mjs +1 -1
  99. package/dist/request/RequestParameterBuilder.mjs +1 -1
  100. package/dist/request/RequestValidator.mjs +1 -1
  101. package/dist/request/ScopeSet.mjs +1 -1
  102. package/dist/response/ResponseHandler.d.ts +2 -2
  103. package/dist/response/ResponseHandler.d.ts.map +1 -1
  104. package/dist/response/ResponseHandler.mjs +30 -32
  105. package/dist/response/ResponseHandler.mjs.map +1 -1
  106. package/dist/telemetry/performance/PerformanceClient.mjs +1 -1
  107. package/dist/telemetry/performance/PerformanceEvent.d.ts +17 -1
  108. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  109. package/dist/telemetry/performance/PerformanceEvent.mjs +9 -2
  110. package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
  111. package/dist/telemetry/performance/StubPerformanceClient.mjs +1 -1
  112. package/dist/telemetry/server/ServerTelemetryManager.mjs +1 -1
  113. package/dist/url/UrlString.mjs +1 -1
  114. package/dist/utils/Constants.mjs +1 -1
  115. package/dist/utils/FunctionWrappers.mjs +1 -1
  116. package/dist/utils/ProtocolUtils.mjs +1 -1
  117. package/dist/utils/StringUtils.mjs +1 -1
  118. package/dist/utils/TimeUtils.mjs +1 -1
  119. package/package.json +1 -1
  120. package/src/authority/Authority.ts +205 -127
  121. package/src/authority/AuthorityFactory.ts +4 -4
  122. package/src/authority/AuthorityMetadata.ts +151 -390
  123. package/src/authority/AuthorityOptions.ts +9 -0
  124. package/src/cache/CacheManager.ts +115 -56
  125. package/src/cache/entities/AccessTokenEntity.ts +13 -149
  126. package/src/cache/entities/AccountEntity.ts +0 -3
  127. package/src/cache/entities/CredentialEntity.ts +16 -200
  128. package/src/cache/entities/IdTokenEntity.ts +4 -64
  129. package/src/cache/entities/RefreshTokenEntity.ts +2 -69
  130. package/src/cache/utils/CacheHelpers.ts +306 -0
  131. package/src/cache/utils/CacheTypes.ts +1 -0
  132. package/src/client/AuthorizationCodeClient.ts +10 -4
  133. package/src/client/BaseClient.ts +29 -15
  134. package/src/client/RefreshTokenClient.ts +17 -7
  135. package/src/client/SilentFlowClient.ts +49 -49
  136. package/src/error/ClientAuthError.ts +8 -0
  137. package/src/error/ClientAuthErrorCodes.ts +1 -0
  138. package/src/index.ts +7 -1
  139. package/src/packageMetadata.ts +1 -1
  140. package/src/response/ResponseHandler.ts +45 -44
  141. package/src/telemetry/performance/PerformanceEvent.ts +24 -2
  142. package/dist/cache/entities/AccessTokenEntity.mjs +0 -121
  143. package/dist/cache/entities/AccessTokenEntity.mjs.map +0 -1
  144. package/dist/cache/entities/CredentialEntity.mjs +0 -145
  145. package/dist/cache/entities/CredentialEntity.mjs.map +0 -1
  146. package/dist/cache/entities/IdTokenEntity.mjs +0 -64
  147. package/dist/cache/entities/IdTokenEntity.mjs.map +0 -1
  148. package/dist/cache/entities/RefreshTokenEntity.mjs +0 -67
  149. package/dist/cache/entities/RefreshTokenEntity.mjs.map +0 -1
@@ -21,6 +21,7 @@ import {
21
21
  Separators,
22
22
  } from "../utils/Constants";
23
23
  import { CredentialEntity } from "./entities/CredentialEntity";
24
+ import { generateCredentialKey } from "./utils/CacheHelpers";
24
25
  import { ScopeSet } from "../request/ScopeSet";
25
26
  import { AccountEntity } from "./entities/AccountEntity";
26
27
  import { AccessTokenEntity } from "./entities/AccessTokenEntity";
@@ -42,6 +43,9 @@ import { BaseAuthRequest } from "../request/BaseAuthRequest";
42
43
  import { Logger } from "../logger/Logger";
43
44
  import { name, version } from "../packageMetadata";
44
45
  import { StoreInCache } from "../request/StoreInCache";
46
+ import { getAliasesFromStaticSources } from "../authority/AuthorityMetadata";
47
+ import { StaticAuthorityOptions } from "../authority/AuthorityOptions";
48
+ import { TokenClaims } from "../account/TokenClaims";
45
49
 
46
50
  /**
47
51
  * Interface class which implement cache storage functions used by MSAL to perform validity checks, and store tokens.
@@ -52,11 +56,18 @@ export abstract class CacheManager implements ICacheManager {
52
56
  protected cryptoImpl: ICrypto;
53
57
  // Instance of logger for functions defined in the msal-common layer
54
58
  private commonLogger: Logger;
55
-
56
- constructor(clientId: string, cryptoImpl: ICrypto, logger: Logger) {
59
+ private staticAuthorityOptions?: StaticAuthorityOptions;
60
+
61
+ constructor(
62
+ clientId: string,
63
+ cryptoImpl: ICrypto,
64
+ logger: Logger,
65
+ staticAuthorityOptions?: StaticAuthorityOptions
66
+ ) {
57
67
  this.clientId = clientId;
58
68
  this.cryptoImpl = cryptoImpl;
59
69
  this.commonLogger = logger.clone(name, version);
70
+ this.staticAuthorityOptions = staticAuthorityOptions;
60
71
  }
61
72
 
62
73
  /**
@@ -226,67 +237,99 @@ export abstract class CacheManager implements ICacheManager {
226
237
  * @returns Array of AccountInfo objects in cache
227
238
  */
228
239
  getAllAccounts(accountFilter?: AccountFilter): AccountInfo[] {
229
- if (accountFilter) {
230
- return this.getAccountsFilteredBy(accountFilter).map(
231
- (accountEntity) => {
232
- return accountEntity.getAccountInfo();
233
- }
234
- );
235
- }
236
-
237
- const allAccountKeys = this.getAccountKeys();
238
- if (allAccountKeys.length < 1) {
239
- return [];
240
- }
241
-
242
- const accountEntities: AccountEntity[] = allAccountKeys.reduce(
243
- (accounts: AccountEntity[], key: string) => {
244
- const entity: AccountEntity | null = this.getAccount(key);
245
-
246
- if (!entity) {
247
- return accounts;
240
+ const validAccounts: AccountInfo[] = [];
241
+ this.getAccountsFilteredBy(accountFilter || {}).forEach(
242
+ (accountEntity: AccountEntity) => {
243
+ const accountInfo = this.getAccountInfoFromEntity(
244
+ accountEntity,
245
+ accountFilter
246
+ );
247
+ if (accountInfo) {
248
+ validAccounts.push(accountInfo);
248
249
  }
249
- accounts.push(entity);
250
- return accounts;
251
- },
252
- []
253
- );
254
-
255
- const allAccounts = accountEntities.map<AccountInfo>(
256
- (accountEntity) => {
257
- return this.getAccountInfoFromEntity(accountEntity);
258
250
  }
259
251
  );
260
- return allAccounts;
252
+ return validAccounts;
261
253
  }
262
254
 
263
255
  /**
264
256
  * Gets accountInfo object based on provided filters
265
257
  */
266
258
  getAccountInfoFilteredBy(accountFilter: AccountFilter): AccountInfo | null {
267
- const allAccounts = this.getAccountsFilteredBy(accountFilter);
268
- if (allAccounts.length > 0) {
269
- return this.getAccountInfoFromEntity(allAccounts[0]);
259
+ const allAccounts = this.getAllAccounts(accountFilter);
260
+ if (allAccounts.length > 1) {
261
+ // If one or more accounts are found, further filter to the first account that has an ID token
262
+ return allAccounts.filter((account) => {
263
+ return !!account.idTokenClaims;
264
+ })[0];
265
+ } else if (allAccounts.length === 1) {
266
+ // If only one account is found, return it regardless of whether a matching ID token was found
267
+ return allAccounts[0];
268
+ } else {
269
+ return null;
270
+ }
271
+ }
272
+
273
+ /**
274
+ * Returns a single matching
275
+ * @param accountFilter
276
+ * @returns
277
+ */
278
+ getBaseAccountInfo(accountFilter: AccountFilter): AccountInfo | null {
279
+ const accountEntities = this.getAccountsFilteredBy(accountFilter);
280
+ if (accountEntities.length > 0) {
281
+ return accountEntities[0].getAccountInfo();
270
282
  } else {
271
283
  return null;
272
284
  }
273
285
  }
274
286
 
275
287
  private getAccountInfoFromEntity(
276
- accountEntity: AccountEntity
277
- ): AccountInfo {
288
+ accountEntity: AccountEntity,
289
+ accountFilter?: AccountFilter
290
+ ): AccountInfo | null {
278
291
  const accountInfo = accountEntity.getAccountInfo();
279
292
  const idToken = this.getIdToken(accountInfo);
280
293
  if (idToken) {
281
- accountInfo.idToken = idToken.secret;
282
- accountInfo.idTokenClaims = extractTokenClaims(
294
+ const idTokenClaims = extractTokenClaims(
283
295
  idToken.secret,
284
296
  this.cryptoImpl.base64Decode
285
297
  );
298
+
299
+ if (
300
+ this.idTokenClaimsMatchAccountFilter(
301
+ idTokenClaims,
302
+ accountFilter
303
+ )
304
+ ) {
305
+ accountInfo.idToken = idToken.secret;
306
+ accountInfo.idTokenClaims = idTokenClaims;
307
+ return accountInfo;
308
+ }
286
309
  }
287
310
  return accountInfo;
288
311
  }
289
312
 
313
+ private idTokenClaimsMatchAccountFilter(
314
+ idTokenClaims: TokenClaims,
315
+ accountFilter?: AccountFilter
316
+ ): boolean {
317
+ if (accountFilter) {
318
+ if (
319
+ !!accountFilter.loginHint &&
320
+ !this.matchLoginHint(idTokenClaims, accountFilter.loginHint)
321
+ ) {
322
+ return false;
323
+ }
324
+ if (
325
+ !!accountFilter.sid &&
326
+ !this.matchSid(idTokenClaims, accountFilter.sid)
327
+ ) {
328
+ return false;
329
+ }
330
+ }
331
+ return true;
332
+ }
290
333
  /**
291
334
  * saves a cache record
292
335
  * @param cacheRecord
@@ -377,7 +420,6 @@ export abstract class CacheManager implements ICacheManager {
377
420
  getAccountsFilteredBy(accountFilter: AccountFilter): AccountEntity[] {
378
421
  const allAccountKeys = this.getAccountKeys();
379
422
  const matchingAccounts: AccountEntity[] = [];
380
-
381
423
  allAccountKeys.forEach((cacheKey) => {
382
424
  if (
383
425
  !this.isAccountKey(
@@ -449,13 +491,6 @@ export abstract class CacheManager implements ICacheManager {
449
491
  return;
450
492
  }
451
493
 
452
- if (
453
- !!accountFilter.loginHint &&
454
- !this.matchLoginHint(entity, accountFilter.loginHint)
455
- ) {
456
- return;
457
- }
458
-
459
494
  if (
460
495
  !!accountFilter.authorityType &&
461
496
  !this.matchAuthorityType(entity, accountFilter.authorityType)
@@ -926,7 +961,7 @@ export abstract class CacheManager implements ICacheManager {
926
961
  "CacheManager:getIdToken - Multiple id tokens found, clearing them"
927
962
  );
928
963
  idTokens.forEach((idToken) => {
929
- this.removeIdToken(idToken.generateCredentialKey());
964
+ this.removeIdToken(generateCredentialKey(idToken));
930
965
  });
931
966
  return null;
932
967
  }
@@ -957,7 +992,6 @@ export abstract class CacheManager implements ICacheManager {
957
992
  ) {
958
993
  return;
959
994
  }
960
-
961
995
  const idToken = this.getIdTokenCredential(key);
962
996
  if (idToken && this.credentialMatchesFilter(idToken, filter)) {
963
997
  idTokens.push(idToken);
@@ -1083,9 +1117,7 @@ export abstract class CacheManager implements ICacheManager {
1083
1117
  "CacheManager:getAccessToken - Multiple access tokens found, clearing them"
1084
1118
  );
1085
1119
  accessTokens.forEach((accessToken) => {
1086
- void this.removeAccessToken(
1087
- accessToken.generateCredentialKey()
1088
- );
1120
+ void this.removeAccessToken(generateCredentialKey(accessToken));
1089
1121
  });
1090
1122
  return null;
1091
1123
  }
@@ -1391,6 +1423,21 @@ export abstract class CacheManager implements ICacheManager {
1391
1423
  entity: AccountEntity | CredentialEntity | AppMetadataEntity,
1392
1424
  environment: string
1393
1425
  ): boolean {
1426
+ // Check static authority options first for cases where authority metadata has not been resolved and cached yet
1427
+ if (this.staticAuthorityOptions) {
1428
+ const staticAliases = getAliasesFromStaticSources(
1429
+ this.staticAuthorityOptions,
1430
+ this.commonLogger
1431
+ );
1432
+ if (
1433
+ staticAliases.includes(environment) &&
1434
+ staticAliases.includes(entity.environment)
1435
+ ) {
1436
+ return true;
1437
+ }
1438
+ }
1439
+
1440
+ // Query metadata cache if no static authority configuration has aliases that match enviroment
1394
1441
  const cloudMetadata = this.getAuthorityMetadataByAlias(environment);
1395
1442
  if (
1396
1443
  cloudMetadata &&
@@ -1398,7 +1445,6 @@ export abstract class CacheManager implements ICacheManager {
1398
1445
  ) {
1399
1446
  return true;
1400
1447
  }
1401
-
1402
1448
  return false;
1403
1449
  }
1404
1450
 
@@ -1477,22 +1523,35 @@ export abstract class CacheManager implements ICacheManager {
1477
1523
  * @param loginHint
1478
1524
  * @returns
1479
1525
  */
1480
- private matchLoginHint(entity: AccountEntity, loginHint: string): boolean {
1481
- if (entity.idTokenClaims?.login_hint === loginHint) {
1526
+ private matchLoginHint(
1527
+ idTokenClaims: TokenClaims,
1528
+ loginHint: string
1529
+ ): boolean {
1530
+ if (idTokenClaims?.login_hint === loginHint) {
1482
1531
  return true;
1483
1532
  }
1484
1533
 
1485
- if (entity.username === loginHint) {
1534
+ if (idTokenClaims.preferred_username === loginHint) {
1486
1535
  return true;
1487
1536
  }
1488
1537
 
1489
- if (entity.idTokenClaims?.upn === loginHint) {
1538
+ if (idTokenClaims?.upn === loginHint) {
1490
1539
  return true;
1491
1540
  }
1492
1541
 
1493
1542
  return false;
1494
1543
  }
1495
1544
 
1545
+ /**
1546
+ * Helper to match sid
1547
+ * @param idTokenClaims
1548
+ * @param sid
1549
+ * @returns true if the sid claim is present and matches the filter
1550
+ */
1551
+ private matchSid(idTokenClaims: TokenClaims, sid: string): boolean {
1552
+ return !!(idTokenClaims?.sid && idTokenClaims.sid === sid);
1553
+ }
1554
+
1496
1555
  private matchAuthorityType(
1497
1556
  entity: AccountEntity,
1498
1557
  authorityType: string
@@ -4,164 +4,28 @@
4
4
  */
5
5
 
6
6
  import { CredentialEntity } from "./CredentialEntity";
7
- import { CredentialType, AuthenticationScheme } from "../../utils/Constants";
8
- import { TimeUtils } from "../../utils/TimeUtils";
9
- import { ICrypto } from "../../crypto/ICrypto";
10
- import { TokenClaims } from "../../account/TokenClaims";
11
- import {
12
- createClientAuthError,
13
- ClientAuthErrorCodes,
14
- } from "../../error/ClientAuthError";
15
- import { extractTokenClaims } from "../../account/AuthToken";
7
+ import { AuthenticationScheme } from "../../utils/Constants";
16
8
 
17
9
  /**
18
- * ACCESS_TOKEN Credential Type
19
- *
20
- * Key:Value Schema:
21
- *
22
- * Key Example: uid.utid-login.microsoftonline.com-accesstoken-clientId-contoso.com-user.read
23
- *
24
- * Value Schema:
25
- * {
26
- * homeAccountId: home account identifier for the auth scheme,
27
- * environment: entity that issued the token, represented as a full host
28
- * credentialType: Type of credential as a string, can be one of the following: RefreshToken, AccessToken, IdToken, Password, Cookie, Certificate, Other
29
- * clientId: client ID of the application
30
- * secret: Actual credential as a string
31
- * familyId: Family ID identifier, usually only used for refresh tokens
32
- * realm: Full tenant or organizational identifier that the account belongs to
33
- * target: Permissions that are included in the token, or for refresh tokens, the resource identifier.
34
- * cachedAt: Absolute device time when entry was created in the cache.
35
- * expiresOn: Token expiry time, calculated based on current UTC time in seconds. Represented as a string.
36
- * extendedExpiresOn: Additional extended expiry time until when token is valid in case of server-side outage. Represented as string in UTC seconds.
37
- * keyId: used for POP and SSH tokenTypes
38
- * tokenType: Type of the token issued. Usually "Bearer"
39
- * }
10
+ * Access token cache type
40
11
  */
41
- export class AccessTokenEntity extends CredentialEntity {
12
+ export type AccessTokenEntity = CredentialEntity & {
13
+ /** Full tenant or organizational identifier that the account belongs to */
42
14
  realm: string;
15
+ /** Permissions that are included in the token, or for refresh tokens, the resource identifier. */
43
16
  target: string;
17
+ /** Absolute device time when entry was created in the cache. */
44
18
  cachedAt: string;
19
+ /** Token expiry time, calculated based on current UTC time in seconds. Represented as a string. */
45
20
  expiresOn: string;
21
+ /** Additional extended expiry time until when token is valid in case of server-side outage. Represented as string in UTC seconds. */
46
22
  extendedExpiresOn?: string;
23
+ /** Used for proactive refresh */
47
24
  refreshOn?: string;
48
- keyId?: string; // for POP and SSH tokenTypes
25
+ /** Matches the authentication scheme for which the token was issued (i.e. Bearer or pop) */
49
26
  tokenType?: AuthenticationScheme;
27
+ /** Stringified claims object */
50
28
  requestedClaims?: string;
29
+ /** Matches the SHA 256 hash of the claims object included in the token request */
51
30
  requestedClaimsHash?: string;
52
-
53
- /**
54
- * Create AccessTokenEntity
55
- * @param homeAccountId
56
- * @param environment
57
- * @param accessToken
58
- * @param clientId
59
- * @param tenantId
60
- * @param scopes
61
- * @param expiresOn
62
- * @param extExpiresOn
63
- */
64
- static createAccessTokenEntity(
65
- homeAccountId: string,
66
- environment: string,
67
- accessToken: string,
68
- clientId: string,
69
- tenantId: string,
70
- scopes: string,
71
- expiresOn: number,
72
- extExpiresOn: number,
73
- cryptoUtils: ICrypto,
74
- refreshOn?: number,
75
- tokenType?: AuthenticationScheme,
76
- userAssertionHash?: string,
77
- keyId?: string,
78
- requestedClaims?: string,
79
- requestedClaimsHash?: string
80
- ): AccessTokenEntity {
81
- const atEntity: AccessTokenEntity = new AccessTokenEntity();
82
-
83
- atEntity.homeAccountId = homeAccountId;
84
- atEntity.credentialType = CredentialType.ACCESS_TOKEN;
85
- atEntity.secret = accessToken;
86
-
87
- const currentTime = TimeUtils.nowSeconds();
88
- atEntity.cachedAt = currentTime.toString();
89
-
90
- /*
91
- * Token expiry time.
92
- * This value should be  calculated based on the current UTC time measured locally and the value  expires_in Represented as a string in JSON.
93
- */
94
- atEntity.expiresOn = expiresOn.toString();
95
- atEntity.extendedExpiresOn = extExpiresOn.toString();
96
- if (refreshOn) {
97
- atEntity.refreshOn = refreshOn.toString();
98
- }
99
-
100
- atEntity.environment = environment;
101
- atEntity.clientId = clientId;
102
- atEntity.realm = tenantId;
103
- atEntity.target = scopes;
104
- atEntity.userAssertionHash = userAssertionHash;
105
-
106
- atEntity.tokenType = tokenType || AuthenticationScheme.BEARER;
107
-
108
- if (requestedClaims) {
109
- atEntity.requestedClaims = requestedClaims;
110
- atEntity.requestedClaimsHash = requestedClaimsHash;
111
- }
112
-
113
- /*
114
- * Create Access Token With Auth Scheme instead of regular access token
115
- * Cast to lower to handle "bearer" from ADFS
116
- */
117
- if (
118
- atEntity.tokenType?.toLowerCase() !==
119
- AuthenticationScheme.BEARER.toLowerCase()
120
- ) {
121
- atEntity.credentialType =
122
- CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME;
123
- switch (atEntity.tokenType) {
124
- case AuthenticationScheme.POP:
125
- // Make sure keyId is present and add it to credential
126
- const tokenClaims: TokenClaims | null = extractTokenClaims(
127
- accessToken,
128
- cryptoUtils.base64Decode
129
- );
130
- if (!tokenClaims?.cnf?.kid) {
131
- throw createClientAuthError(
132
- ClientAuthErrorCodes.tokenClaimsCnfRequiredForSignedJwt
133
- );
134
- }
135
- atEntity.keyId = tokenClaims.cnf.kid;
136
- break;
137
- case AuthenticationScheme.SSH:
138
- atEntity.keyId = keyId;
139
- }
140
- }
141
-
142
- return atEntity;
143
- }
144
-
145
- /**
146
- * Validates an entity: checks for all expected params
147
- * @param entity
148
- */
149
- static isAccessTokenEntity(entity: object): boolean {
150
- if (!entity) {
151
- return false;
152
- }
153
-
154
- return (
155
- entity.hasOwnProperty("homeAccountId") &&
156
- entity.hasOwnProperty("environment") &&
157
- entity.hasOwnProperty("credentialType") &&
158
- entity.hasOwnProperty("realm") &&
159
- entity.hasOwnProperty("clientId") &&
160
- entity.hasOwnProperty("secret") &&
161
- entity.hasOwnProperty("target") &&
162
- (entity["credentialType"] === CredentialType.ACCESS_TOKEN ||
163
- entity["credentialType"] ===
164
- CredentialType.ACCESS_TOKEN_WITH_AUTH_SCHEME)
165
- );
166
- }
167
- }
31
+ };
@@ -153,8 +153,6 @@ export class AccountEntity {
153
153
  account.realm =
154
154
  accountDetails.idTokenClaims.tid || Constants.EMPTY_STRING;
155
155
 
156
- account.idTokenClaims = accountDetails.idTokenClaims;
157
-
158
156
  // How do you account for MSA CID here?
159
157
  account.localAccountId =
160
158
  accountDetails.idTokenClaims.oid ||
@@ -207,7 +205,6 @@ export class AccountEntity {
207
205
 
208
206
  account.username = accountInfo.username;
209
207
  account.name = accountInfo.name;
210
- account.idTokenClaims = accountInfo.idTokenClaims;
211
208
 
212
209
  account.cloudGraphHostName = cloudGraphHostName;
213
210
  account.msGraphHost = msGraphHost;