@azure/msal-common 14.5.0 → 14.6.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 (135) hide show
  1. package/dist/account/AccountInfo.mjs +1 -1
  2. package/dist/account/AuthToken.mjs +1 -1
  3. package/dist/account/CcsCredential.mjs +1 -1
  4. package/dist/account/ClientInfo.mjs +1 -1
  5. package/dist/account/TokenClaims.mjs +1 -1
  6. package/dist/authority/Authority.d.ts.map +1 -1
  7. package/dist/authority/Authority.mjs +30 -15
  8. package/dist/authority/Authority.mjs.map +1 -1
  9. package/dist/authority/AuthorityFactory.mjs +1 -1
  10. package/dist/authority/AuthorityMetadata.mjs +1 -1
  11. package/dist/authority/AuthorityOptions.mjs +1 -1
  12. package/dist/authority/AuthorityType.mjs +1 -1
  13. package/dist/authority/CloudInstanceDiscoveryErrorResponse.mjs +1 -1
  14. package/dist/authority/CloudInstanceDiscoveryResponse.mjs +1 -1
  15. package/dist/authority/OpenIdConfigResponse.mjs +1 -1
  16. package/dist/authority/ProtocolMode.mjs +1 -1
  17. package/dist/authority/RegionDiscovery.mjs +1 -1
  18. package/dist/cache/CacheManager.d.ts +0 -9
  19. package/dist/cache/CacheManager.d.ts.map +1 -1
  20. package/dist/cache/CacheManager.mjs +1 -27
  21. package/dist/cache/CacheManager.mjs.map +1 -1
  22. package/dist/cache/entities/AccountEntity.mjs +1 -1
  23. package/dist/cache/entities/AppMetadataEntity.d.ts +6 -34
  24. package/dist/cache/entities/AppMetadataEntity.d.ts.map +1 -1
  25. package/dist/cache/entities/AuthorityMetadataEntity.d.ts +2 -35
  26. package/dist/cache/entities/AuthorityMetadataEntity.d.ts.map +1 -1
  27. package/dist/cache/entities/CacheRecord.mjs +1 -1
  28. package/dist/cache/entities/RefreshTokenEntity.d.ts +3 -1
  29. package/dist/cache/entities/RefreshTokenEntity.d.ts.map +1 -1
  30. package/dist/cache/entities/ThrottlingEntity.d.ts +2 -8
  31. package/dist/cache/entities/ThrottlingEntity.d.ts.map +1 -1
  32. package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
  33. package/dist/cache/utils/CacheHelpers.d.ts +31 -1
  34. package/dist/cache/utils/CacheHelpers.d.ts.map +1 -1
  35. package/dist/cache/utils/CacheHelpers.mjs +97 -4
  36. package/dist/cache/utils/CacheHelpers.mjs.map +1 -1
  37. package/dist/client/AuthorizationCodeClient.mjs +1 -1
  38. package/dist/client/BaseClient.mjs +1 -1
  39. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  40. package/dist/client/RefreshTokenClient.mjs +22 -3
  41. package/dist/client/RefreshTokenClient.mjs.map +1 -1
  42. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  43. package/dist/client/SilentFlowClient.mjs +19 -8
  44. package/dist/client/SilentFlowClient.mjs.map +1 -1
  45. package/dist/config/ClientConfiguration.mjs +1 -1
  46. package/dist/constants/AADServerParamKeys.d.ts +1 -0
  47. package/dist/constants/AADServerParamKeys.d.ts.map +1 -1
  48. package/dist/constants/AADServerParamKeys.mjs +3 -2
  49. package/dist/constants/AADServerParamKeys.mjs.map +1 -1
  50. package/dist/crypto/ICrypto.mjs +1 -1
  51. package/dist/crypto/JoseHeader.mjs +1 -1
  52. package/dist/crypto/PopTokenGenerator.mjs +1 -1
  53. package/dist/error/AuthError.mjs +1 -1
  54. package/dist/error/AuthErrorCodes.mjs +1 -1
  55. package/dist/error/ClientAuthError.mjs +1 -1
  56. package/dist/error/ClientAuthErrorCodes.mjs +1 -1
  57. package/dist/error/ClientConfigurationError.mjs +1 -1
  58. package/dist/error/ClientConfigurationErrorCodes.mjs +1 -1
  59. package/dist/error/InteractionRequiredAuthError.d.ts +4 -0
  60. package/dist/error/InteractionRequiredAuthError.d.ts.map +1 -1
  61. package/dist/error/InteractionRequiredAuthError.mjs +10 -2
  62. package/dist/error/InteractionRequiredAuthError.mjs.map +1 -1
  63. package/dist/error/InteractionRequiredAuthErrorCodes.d.ts +2 -0
  64. package/dist/error/InteractionRequiredAuthErrorCodes.d.ts.map +1 -1
  65. package/dist/error/InteractionRequiredAuthErrorCodes.mjs +4 -2
  66. package/dist/error/InteractionRequiredAuthErrorCodes.mjs.map +1 -1
  67. package/dist/error/JoseHeaderError.mjs +1 -1
  68. package/dist/error/JoseHeaderErrorCodes.mjs +1 -1
  69. package/dist/error/ServerError.mjs +1 -1
  70. package/dist/index.cjs +3065 -3088
  71. package/dist/index.cjs.map +1 -1
  72. package/dist/index.mjs +1 -4
  73. package/dist/index.mjs.map +1 -1
  74. package/dist/logger/Logger.mjs +1 -1
  75. package/dist/network/INetworkModule.mjs +1 -1
  76. package/dist/network/NetworkManager.mjs +1 -1
  77. package/dist/network/ThrottlingUtils.mjs +1 -1
  78. package/dist/packageMetadata.d.ts +1 -1
  79. package/dist/packageMetadata.mjs +2 -2
  80. package/dist/request/AuthenticationHeaderParser.mjs +1 -1
  81. package/dist/request/CommonSilentFlowRequest.d.ts +7 -0
  82. package/dist/request/CommonSilentFlowRequest.d.ts.map +1 -1
  83. package/dist/request/RequestParameterBuilder.mjs +1 -1
  84. package/dist/request/RequestValidator.mjs +1 -1
  85. package/dist/request/ScopeSet.mjs +1 -1
  86. package/dist/response/ResponseHandler.d.ts +1 -1
  87. package/dist/response/ResponseHandler.d.ts.map +1 -1
  88. package/dist/response/ResponseHandler.mjs +22 -9
  89. package/dist/response/ResponseHandler.mjs.map +1 -1
  90. package/dist/response/ServerAuthorizationTokenResponse.d.ts +1 -0
  91. package/dist/response/ServerAuthorizationTokenResponse.d.ts.map +1 -1
  92. package/dist/telemetry/performance/IPerformanceClient.d.ts +6 -0
  93. package/dist/telemetry/performance/IPerformanceClient.d.ts.map +1 -1
  94. package/dist/telemetry/performance/PerformanceClient.d.ts +9 -2
  95. package/dist/telemetry/performance/PerformanceClient.d.ts.map +1 -1
  96. package/dist/telemetry/performance/PerformanceClient.mjs +17 -13
  97. package/dist/telemetry/performance/PerformanceClient.mjs.map +1 -1
  98. package/dist/telemetry/performance/PerformanceEvent.mjs +1 -1
  99. package/dist/telemetry/performance/StubPerformanceClient.d.ts.map +1 -1
  100. package/dist/telemetry/performance/StubPerformanceClient.mjs +1 -1
  101. package/dist/telemetry/performance/StubPerformanceClient.mjs.map +1 -1
  102. package/dist/telemetry/server/ServerTelemetryManager.mjs +1 -1
  103. package/dist/url/UrlString.mjs +1 -1
  104. package/dist/utils/Constants.mjs +1 -1
  105. package/dist/utils/FunctionWrappers.mjs +1 -1
  106. package/dist/utils/ProtocolUtils.mjs +1 -1
  107. package/dist/utils/StringUtils.mjs +1 -1
  108. package/dist/utils/TimeUtils.mjs +1 -1
  109. package/dist/utils/UrlUtils.mjs +1 -1
  110. package/package.json +1 -1
  111. package/src/authority/Authority.ts +55 -16
  112. package/src/cache/CacheManager.ts +0 -54
  113. package/src/cache/entities/AppMetadataEntity.ts +6 -81
  114. package/src/cache/entities/AuthorityMetadataEntity.ts +2 -94
  115. package/src/cache/entities/RefreshTokenEntity.ts +3 -1
  116. package/src/cache/entities/ThrottlingEntity.ts +2 -24
  117. package/src/cache/utils/CacheHelpers.ts +137 -1
  118. package/src/client/RefreshTokenClient.ts +40 -7
  119. package/src/client/SilentFlowClient.ts +30 -10
  120. package/src/constants/AADServerParamKeys.ts +1 -0
  121. package/src/error/InteractionRequiredAuthError.ts +12 -0
  122. package/src/error/InteractionRequiredAuthErrorCodes.ts +2 -0
  123. package/src/packageMetadata.ts +1 -1
  124. package/src/request/CommonSilentFlowRequest.ts +7 -0
  125. package/src/response/ResponseHandler.ts +26 -10
  126. package/src/response/ServerAuthorizationTokenResponse.ts +1 -0
  127. package/src/telemetry/performance/IPerformanceClient.ts +6 -0
  128. package/src/telemetry/performance/PerformanceClient.ts +24 -31
  129. package/src/telemetry/performance/StubPerformanceClient.ts +0 -1
  130. package/dist/cache/entities/AppMetadataEntity.mjs +0 -73
  131. package/dist/cache/entities/AppMetadataEntity.mjs.map +0 -1
  132. package/dist/cache/entities/AuthorityMetadataEntity.mjs +0 -86
  133. package/dist/cache/entities/AuthorityMetadataEntity.mjs.map +0 -1
  134. package/dist/cache/entities/ThrottlingEntity.mjs +0 -30
  135. package/dist/cache/entities/ThrottlingEntity.mjs.map +0 -1
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v14.5.0 2023-12-01 */
1
+ /*! @azure/msal-common v14.6.0 2024-01-09 */
2
2
  'use strict';
3
3
  /*
4
4
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v14.5.0 2023-12-01 */
1
+ /*! @azure/msal-common v14.6.0 2024-01-09 */
2
2
  'use strict';
3
3
  import { createClientAuthError } from '../error/ClientAuthError.mjs';
4
4
  import { hashNotDeserialized } from '../error/ClientAuthErrorCodes.mjs';
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "type": "git",
11
11
  "url": "https://github.com/AzureAD/microsoft-authentication-library-for-js.git"
12
12
  },
13
- "version": "14.5.0",
13
+ "version": "14.6.0",
14
14
  "description": "Microsoft Authentication Library for js",
15
15
  "keywords": [
16
16
  "implicit",
@@ -57,6 +57,7 @@ import { AuthError } from "../error/AuthError";
57
57
  import { IPerformanceClient } from "../telemetry/performance/IPerformanceClient";
58
58
  import { PerformanceEvents } from "../telemetry/performance/PerformanceEvent";
59
59
  import { invokeAsync } from "../utils/FunctionWrappers";
60
+ import * as CacheHelpers from "../cache/utils/CacheHelpers";
60
61
 
61
62
  /**
62
63
  * The authority class validates the authority URIs used by the user, and retrieves the OpenID Configuration Data from the
@@ -429,13 +430,24 @@ export class Authority {
429
430
  * @returns
430
431
  */
431
432
  private getCurrentMetadataEntity(): AuthorityMetadataEntity {
432
- let metadataEntity = this.cacheManager.getAuthorityMetadataByAlias(
433
- this.hostnameAndPort
434
- );
433
+ let metadataEntity: AuthorityMetadataEntity | null =
434
+ this.cacheManager.getAuthorityMetadataByAlias(this.hostnameAndPort);
435
435
 
436
436
  if (!metadataEntity) {
437
- metadataEntity = new AuthorityMetadataEntity();
438
- metadataEntity.updateCanonicalAuthority(this.canonicalAuthority);
437
+ metadataEntity = {
438
+ aliases: [],
439
+ preferred_cache: this.hostnameAndPort,
440
+ preferred_network: this.hostnameAndPort,
441
+ canonical_authority: this.canonicalAuthority,
442
+ authorization_endpoint: "",
443
+ token_endpoint: "",
444
+ end_session_endpoint: "",
445
+ issuer: "",
446
+ aliasesFromNetwork: false,
447
+ endpointsFromNetwork: false,
448
+ expiresAt: CacheHelpers.generateAuthorityMetadataExpiresAt(),
449
+ jwks_uri: "",
450
+ };
439
451
  }
440
452
  return metadataEntity;
441
453
  }
@@ -460,8 +472,9 @@ export class Authority {
460
472
  endpointMetadataResult?.source !== AuthorityMetadataSource.CACHE
461
473
  ) {
462
474
  // Reset the expiration time unless both values came from a successful cache lookup
463
- metadataEntity.resetExpiresAt();
464
- metadataEntity.updateCanonicalAuthority(this.canonicalAuthority);
475
+ metadataEntity.expiresAt =
476
+ CacheHelpers.generateAuthorityMetadataExpiresAt();
477
+ metadataEntity.canonical_authority = this.canonicalAuthority;
465
478
  }
466
479
 
467
480
  const cacheKey = this.cacheManager.generateAuthorityMetadataCacheKey(
@@ -506,10 +519,13 @@ export class Authority {
506
519
  this.performanceClient,
507
520
  this.correlationId
508
521
  )(localMetadata.metadata);
509
- metadataEntity.updateEndpointMetadata(
522
+ CacheHelpers.updateAuthorityEndpointMetadata(
523
+ metadataEntity,
510
524
  hardcodedMetadata,
511
525
  false
512
526
  );
527
+ metadataEntity.canonical_authority =
528
+ this.canonicalAuthority;
513
529
  }
514
530
  }
515
531
  }
@@ -536,7 +552,11 @@ export class Authority {
536
552
  )(metadata);
537
553
  }
538
554
 
539
- metadataEntity.updateEndpointMetadata(metadata, true);
555
+ CacheHelpers.updateAuthorityEndpointMetadata(
556
+ metadataEntity,
557
+ metadata,
558
+ true
559
+ );
540
560
  return AuthorityMetadataSource.NETWORK;
541
561
  } else {
542
562
  // Metadata could not be obtained from the config, cache, network or hardcoded values
@@ -567,7 +587,11 @@ export class Authority {
567
587
  this.logger.verbose(
568
588
  "Found endpoint metadata in authority configuration"
569
589
  );
570
- metadataEntity.updateEndpointMetadata(configMetadata, false);
590
+ CacheHelpers.updateAuthorityEndpointMetadata(
591
+ metadataEntity,
592
+ configMetadata,
593
+ false
594
+ );
571
595
  return {
572
596
  source: AuthorityMetadataSource.CONFIG,
573
597
  };
@@ -586,7 +610,11 @@ export class Authority {
586
610
  const hardcodedMetadata =
587
611
  this.getEndpointMetadataFromHardcodedValues();
588
612
  if (hardcodedMetadata) {
589
- metadataEntity.updateEndpointMetadata(hardcodedMetadata, false);
613
+ CacheHelpers.updateAuthorityEndpointMetadata(
614
+ metadataEntity,
615
+ hardcodedMetadata,
616
+ false
617
+ );
590
618
  return {
591
619
  source: AuthorityMetadataSource.HARDCODED_VALUES,
592
620
  metadata: hardcodedMetadata,
@@ -599,7 +627,8 @@ export class Authority {
599
627
  }
600
628
 
601
629
  // Check cached metadata entity expiration status
602
- const metadataEntityExpired = metadataEntity.isExpired();
630
+ const metadataEntityExpired =
631
+ CacheHelpers.isAuthorityMetadataExpired(metadataEntity);
603
632
  if (
604
633
  this.isAuthoritySameType(metadataEntity) &&
605
634
  metadataEntity.endpointsFromNetwork &&
@@ -801,7 +830,11 @@ export class Authority {
801
830
  )();
802
831
 
803
832
  if (metadata) {
804
- metadataEntity.updateCloudDiscoveryMetadata(metadata, true);
833
+ CacheHelpers.updateCloudDiscoveryMetadata(
834
+ metadataEntity,
835
+ metadata,
836
+ true
837
+ );
805
838
  return AuthorityMetadataSource.NETWORK;
806
839
  }
807
840
 
@@ -839,7 +872,11 @@ export class Authority {
839
872
  this.logger.verbose(
840
873
  "Found cloud discovery metadata in authority configuration"
841
874
  );
842
- metadataEntity.updateCloudDiscoveryMetadata(metadata, false);
875
+ CacheHelpers.updateCloudDiscoveryMetadata(
876
+ metadataEntity,
877
+ metadata,
878
+ false
879
+ );
843
880
  return AuthorityMetadataSource.CONFIG;
844
881
  }
845
882
 
@@ -861,7 +898,8 @@ export class Authority {
861
898
  this.logger.verbose(
862
899
  "Found cloud discovery metadata from hardcoded values."
863
900
  );
864
- metadataEntity.updateCloudDiscoveryMetadata(
901
+ CacheHelpers.updateCloudDiscoveryMetadata(
902
+ metadataEntity,
865
903
  hardcodedMetadata,
866
904
  false
867
905
  );
@@ -873,7 +911,8 @@ export class Authority {
873
911
  );
874
912
  }
875
913
 
876
- const metadataEntityExpired = metadataEntity.isExpired();
914
+ const metadataEntityExpired =
915
+ CacheHelpers.isAuthorityMetadataExpired(metadataEntity);
877
916
  if (
878
917
  this.isAuthoritySameType(metadataEntity) &&
879
918
  metadataEntity.aliasesFromNetwork &&
@@ -49,7 +49,6 @@ import { BaseAuthRequest } from "../request/BaseAuthRequest";
49
49
  import { Logger } from "../logger/Logger";
50
50
  import { name, version } from "../packageMetadata";
51
51
  import { StoreInCache } from "../request/StoreInCache";
52
- import { getTenantFromAuthorityString } from "../authority/Authority";
53
52
  import { getAliasesFromStaticSources } from "../authority/AuthorityMetadata";
54
53
  import { StaticAuthorityOptions } from "../authority/AuthorityOptions";
55
54
  import { TokenClaims } from "../account/TokenClaims";
@@ -1128,59 +1127,6 @@ export abstract class CacheManager implements ICacheManager {
1128
1127
  return true;
1129
1128
  }
1130
1129
 
1131
- /**
1132
- * Retrieve the cached credentials into a cacherecord
1133
- * @param account {AccountInfo}
1134
- * @param request {BaseAuthRequest}
1135
- * @param environment {string}
1136
- * @param performanceClient {?IPerformanceClient}
1137
- * @param correlationId {?string}
1138
- */
1139
- readCacheRecord(
1140
- account: AccountInfo,
1141
- request: BaseAuthRequest,
1142
- environment: string,
1143
- performanceClient?: IPerformanceClient,
1144
- correlationId?: string
1145
- ): CacheRecord {
1146
- // Use authority tenantId for cache lookup filter if it's defined, otherwise use tenantId from account passed in
1147
- const requestTenantId =
1148
- account.tenantId || getTenantFromAuthorityString(request.authority);
1149
- const tokenKeys = this.getTokenKeys();
1150
- const cachedAccount = this.readAccountFromCache(account);
1151
- const cachedIdToken = this.getIdToken(
1152
- account,
1153
- tokenKeys,
1154
- requestTenantId,
1155
- performanceClient,
1156
- correlationId
1157
- );
1158
- const cachedAccessToken = this.getAccessToken(
1159
- account,
1160
- request,
1161
- tokenKeys,
1162
- requestTenantId,
1163
- performanceClient,
1164
- correlationId
1165
- );
1166
- const cachedRefreshToken = this.getRefreshToken(
1167
- account,
1168
- false,
1169
- tokenKeys,
1170
- performanceClient,
1171
- correlationId
1172
- );
1173
- const cachedAppMetadata = this.readAppMetadataFromCache(environment);
1174
-
1175
- return {
1176
- account: cachedAccount,
1177
- idToken: cachedIdToken,
1178
- accessToken: cachedAccessToken,
1179
- refreshToken: cachedRefreshToken,
1180
- appMetadata: cachedAppMetadata,
1181
- };
1182
- }
1183
-
1184
1130
  /**
1185
1131
  * Retrieve AccountEntity from cache
1186
1132
  * @param account
@@ -3,89 +3,14 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { APP_METADATA, Separators } from "../../utils/Constants";
7
-
8
6
  /**
9
- * APP_METADATA Cache
10
- *
11
- * Key:Value Schema:
12
- *
13
- * Key: appmetadata-<environment>-<client_id>
14
- *
15
- * Value:
16
- * {
17
- * clientId: client ID of the application
18
- * environment: entity that issued the token, represented as a full host
19
- * familyId: Family ID identifier, '1' represents Microsoft Family
20
- * }
7
+ * App Metadata Cache Type
21
8
  */
22
- export class AppMetadataEntity {
9
+ export type AppMetadataEntity = {
10
+ /** clientId of the application */
23
11
  clientId: string;
12
+ /** entity that issued the token, represented as a full host */
24
13
  environment: string;
14
+ /** Family identifier, '1' represents Microsoft Family */
25
15
  familyId?: string;
26
-
27
- /**
28
- * Generate AppMetadata Cache Key as per the schema: appmetadata-<environment>-<client_id>
29
- */
30
- generateAppMetadataKey(): string {
31
- return AppMetadataEntity.generateAppMetadataCacheKey(
32
- this.environment,
33
- this.clientId
34
- );
35
- }
36
-
37
- /**
38
- * Generate AppMetadata Cache Key
39
- */
40
- static generateAppMetadataCacheKey(
41
- environment: string,
42
- clientId: string
43
- ): string {
44
- const appMetaDataKeyArray: Array<string> = [
45
- APP_METADATA,
46
- environment,
47
- clientId,
48
- ];
49
- return appMetaDataKeyArray
50
- .join(Separators.CACHE_KEY_SEPARATOR)
51
- .toLowerCase();
52
- }
53
-
54
- /**
55
- * Creates AppMetadataEntity
56
- * @param clientId
57
- * @param environment
58
- * @param familyId
59
- */
60
- static createAppMetadataEntity(
61
- clientId: string,
62
- environment: string,
63
- familyId?: string
64
- ): AppMetadataEntity {
65
- const appMetadata = new AppMetadataEntity();
66
-
67
- appMetadata.clientId = clientId;
68
- appMetadata.environment = environment;
69
- if (familyId) {
70
- appMetadata.familyId = familyId;
71
- }
72
-
73
- return appMetadata;
74
- }
75
-
76
- /**
77
- * Validates an entity: checks for all expected params
78
- * @param entity
79
- */
80
- static isAppMetadataEntity(key: string, entity: object): boolean {
81
- if (!entity) {
82
- return false;
83
- }
84
-
85
- return (
86
- key.indexOf(APP_METADATA) === 0 &&
87
- entity.hasOwnProperty("clientId") &&
88
- entity.hasOwnProperty("environment")
89
- );
90
- }
91
- }
16
+ };
@@ -3,13 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { CloudDiscoveryMetadata } from "../../authority/CloudDiscoveryMetadata";
7
- import { OpenIdConfigResponse } from "../../authority/OpenIdConfigResponse";
8
- import { AUTHORITY_METADATA_CONSTANTS } from "../../utils/Constants";
9
- import { TimeUtils } from "../../utils/TimeUtils";
10
-
11
6
  /** @internal */
12
- export class AuthorityMetadataEntity {
7
+ export type AuthorityMetadataEntity = {
13
8
  aliases: Array<string>;
14
9
  preferred_cache: string;
15
10
  preferred_network: string;
@@ -22,91 +17,4 @@ export class AuthorityMetadataEntity {
22
17
  endpointsFromNetwork: boolean;
23
18
  expiresAt: number;
24
19
  jwks_uri: string;
25
-
26
- constructor() {
27
- this.expiresAt =
28
- TimeUtils.nowSeconds() +
29
- AUTHORITY_METADATA_CONSTANTS.REFRESH_TIME_SECONDS;
30
- }
31
-
32
- /**
33
- * Update the entity with new aliases, preferred_cache and preferred_network values
34
- * @param metadata
35
- * @param fromNetwork
36
- */
37
- updateCloudDiscoveryMetadata(
38
- metadata: CloudDiscoveryMetadata,
39
- fromNetwork: boolean
40
- ): void {
41
- this.aliases = metadata.aliases;
42
- this.preferred_cache = metadata.preferred_cache;
43
- this.preferred_network = metadata.preferred_network;
44
- this.aliasesFromNetwork = fromNetwork;
45
- }
46
-
47
- /**
48
- * Update the entity with new endpoints
49
- * @param metadata
50
- * @param fromNetwork
51
- */
52
- updateEndpointMetadata(
53
- metadata: OpenIdConfigResponse,
54
- fromNetwork: boolean
55
- ): void {
56
- this.authorization_endpoint = metadata.authorization_endpoint;
57
- this.token_endpoint = metadata.token_endpoint;
58
- this.end_session_endpoint = metadata.end_session_endpoint;
59
- this.issuer = metadata.issuer;
60
- this.endpointsFromNetwork = fromNetwork;
61
- this.jwks_uri = metadata.jwks_uri;
62
- }
63
-
64
- /**
65
- * Save the authority that was used to create this cache entry
66
- * @param authority
67
- */
68
- updateCanonicalAuthority(authority: string): void {
69
- this.canonical_authority = authority;
70
- }
71
-
72
- /**
73
- * Reset the exiresAt value
74
- */
75
- resetExpiresAt(): void {
76
- this.expiresAt =
77
- TimeUtils.nowSeconds() +
78
- AUTHORITY_METADATA_CONSTANTS.REFRESH_TIME_SECONDS;
79
- }
80
-
81
- /**
82
- * Returns whether or not the data needs to be refreshed
83
- */
84
- isExpired(): boolean {
85
- return this.expiresAt <= TimeUtils.nowSeconds();
86
- }
87
-
88
- /**
89
- * Validates an entity: checks for all expected params
90
- * @param entity
91
- */
92
- static isAuthorityMetadataEntity(key: string, entity: object): boolean {
93
- if (!entity) {
94
- return false;
95
- }
96
-
97
- return (
98
- key.indexOf(AUTHORITY_METADATA_CONSTANTS.CACHE_KEY) === 0 &&
99
- entity.hasOwnProperty("aliases") &&
100
- entity.hasOwnProperty("preferred_cache") &&
101
- entity.hasOwnProperty("preferred_network") &&
102
- entity.hasOwnProperty("canonical_authority") &&
103
- entity.hasOwnProperty("authorization_endpoint") &&
104
- entity.hasOwnProperty("token_endpoint") &&
105
- entity.hasOwnProperty("issuer") &&
106
- entity.hasOwnProperty("aliasesFromNetwork") &&
107
- entity.hasOwnProperty("endpointsFromNetwork") &&
108
- entity.hasOwnProperty("expiresAt") &&
109
- entity.hasOwnProperty("jwks_uri")
110
- );
111
- }
112
- }
20
+ };
@@ -8,4 +8,6 @@ import { CredentialEntity } from "./CredentialEntity";
8
8
  /**
9
9
  * Refresh Token Cache Type
10
10
  */
11
- export type RefreshTokenEntity = CredentialEntity;
11
+ export type RefreshTokenEntity = CredentialEntity & {
12
+ expiresOn?: string;
13
+ };
@@ -3,9 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { ThrottlingConstants } from "../../utils/Constants";
7
-
8
- export class ThrottlingEntity {
6
+ export type ThrottlingEntity = {
9
7
  // Unix-time value representing the expiration of the throttle
10
8
  throttleTime: number;
11
9
  // Information provided by the server
@@ -13,24 +11,4 @@ export class ThrottlingEntity {
13
11
  errorCodes?: Array<string>;
14
12
  errorMessage?: string;
15
13
  subError?: string;
16
-
17
- /**
18
- * validates if a given cache entry is "Throttling", parses <key,value>
19
- * @param key
20
- * @param entity
21
- */
22
- static isThrottlingEntity(key: string, entity?: object): boolean {
23
- let validateKey: boolean = false;
24
- if (key) {
25
- validateKey =
26
- key.indexOf(ThrottlingConstants.THROTTLING_PREFIX) === 0;
27
- }
28
-
29
- let validateEntity: boolean = true;
30
- if (entity) {
31
- validateEntity = entity.hasOwnProperty("throttleTime");
32
- }
33
-
34
- return validateKey && validateEntity;
35
- }
36
- }
14
+ };
@@ -5,18 +5,25 @@
5
5
 
6
6
  import { extractTokenClaims } from "../../account/AuthToken";
7
7
  import { TokenClaims } from "../../account/TokenClaims";
8
+ import { CloudDiscoveryMetadata } from "../../authority/CloudDiscoveryMetadata";
9
+ import { OpenIdConfigResponse } from "../../authority/OpenIdConfigResponse";
8
10
  import {
9
11
  ClientAuthErrorCodes,
10
12
  createClientAuthError,
11
13
  } from "../../error/ClientAuthError";
12
14
  import {
15
+ APP_METADATA,
16
+ AUTHORITY_METADATA_CONSTANTS,
13
17
  AuthenticationScheme,
14
18
  CredentialType,
15
19
  SERVER_TELEM_CONSTANTS,
16
20
  Separators,
21
+ ThrottlingConstants,
17
22
  } from "../../utils/Constants";
18
23
  import { TimeUtils } from "../../utils/TimeUtils";
19
24
  import { AccessTokenEntity } from "../entities/AccessTokenEntity";
25
+ import { AppMetadataEntity } from "../entities/AppMetadataEntity";
26
+ import { AuthorityMetadataEntity } from "../entities/AuthorityMetadataEntity";
20
27
  import { CredentialEntity } from "../entities/CredentialEntity";
21
28
  import { IdTokenEntity } from "../entities/IdTokenEntity";
22
29
  import { RefreshTokenEntity } from "../entities/RefreshTokenEntity";
@@ -168,7 +175,8 @@ export function createRefreshTokenEntity(
168
175
  refreshToken: string,
169
176
  clientId: string,
170
177
  familyId?: string,
171
- userAssertionHash?: string
178
+ userAssertionHash?: string,
179
+ expiresOn?: number
172
180
  ): RefreshTokenEntity {
173
181
  const rtEntity: RefreshTokenEntity = {
174
182
  credentialType: CredentialType.REFRESH_TOKEN,
@@ -186,6 +194,10 @@ export function createRefreshTokenEntity(
186
194
  rtEntity.familyId = familyId;
187
195
  }
188
196
 
197
+ if (expiresOn) {
198
+ rtEntity.expiresOn = expiresOn.toString();
199
+ }
200
+
189
201
  return rtEntity;
190
202
  }
191
203
 
@@ -325,3 +337,127 @@ export function isServerTelemetryEntity(key: string, entity?: object): boolean {
325
337
 
326
338
  return validateKey && validateEntity;
327
339
  }
340
+
341
+ /**
342
+ * validates if a given cache entry is "Throttling", parses <key,value>
343
+ * @param key
344
+ * @param entity
345
+ */
346
+ export function isThrottlingEntity(key: string, entity?: object): boolean {
347
+ let validateKey: boolean = false;
348
+ if (key) {
349
+ validateKey = key.indexOf(ThrottlingConstants.THROTTLING_PREFIX) === 0;
350
+ }
351
+
352
+ let validateEntity: boolean = true;
353
+ if (entity) {
354
+ validateEntity = entity.hasOwnProperty("throttleTime");
355
+ }
356
+
357
+ return validateKey && validateEntity;
358
+ }
359
+
360
+ /**
361
+ * Generate AppMetadata Cache Key as per the schema: appmetadata-<environment>-<client_id>
362
+ */
363
+ export function generateAppMetadataKey({
364
+ environment,
365
+ clientId,
366
+ }: AppMetadataEntity): string {
367
+ const appMetaDataKeyArray: Array<string> = [
368
+ APP_METADATA,
369
+ environment,
370
+ clientId,
371
+ ];
372
+ return appMetaDataKeyArray
373
+ .join(Separators.CACHE_KEY_SEPARATOR)
374
+ .toLowerCase();
375
+ }
376
+
377
+ /*
378
+ * Validates an entity: checks for all expected params
379
+ * @param entity
380
+ */
381
+ export function isAppMetadataEntity(key: string, entity: object): boolean {
382
+ if (!entity) {
383
+ return false;
384
+ }
385
+
386
+ return (
387
+ key.indexOf(APP_METADATA) === 0 &&
388
+ entity.hasOwnProperty("clientId") &&
389
+ entity.hasOwnProperty("environment")
390
+ );
391
+ }
392
+
393
+ /**
394
+ * Validates an entity: checks for all expected params
395
+ * @param entity
396
+ */
397
+ export function isAuthorityMetadataEntity(
398
+ key: string,
399
+ entity: object
400
+ ): boolean {
401
+ if (!entity) {
402
+ return false;
403
+ }
404
+
405
+ return (
406
+ key.indexOf(AUTHORITY_METADATA_CONSTANTS.CACHE_KEY) === 0 &&
407
+ entity.hasOwnProperty("aliases") &&
408
+ entity.hasOwnProperty("preferred_cache") &&
409
+ entity.hasOwnProperty("preferred_network") &&
410
+ entity.hasOwnProperty("canonical_authority") &&
411
+ entity.hasOwnProperty("authorization_endpoint") &&
412
+ entity.hasOwnProperty("token_endpoint") &&
413
+ entity.hasOwnProperty("issuer") &&
414
+ entity.hasOwnProperty("aliasesFromNetwork") &&
415
+ entity.hasOwnProperty("endpointsFromNetwork") &&
416
+ entity.hasOwnProperty("expiresAt") &&
417
+ entity.hasOwnProperty("jwks_uri")
418
+ );
419
+ }
420
+
421
+ /**
422
+ * Reset the exiresAt value
423
+ */
424
+ export function generateAuthorityMetadataExpiresAt(): number {
425
+ return (
426
+ TimeUtils.nowSeconds() +
427
+ AUTHORITY_METADATA_CONSTANTS.REFRESH_TIME_SECONDS
428
+ );
429
+ }
430
+
431
+ export function updateAuthorityEndpointMetadata(
432
+ authorityMetadata: AuthorityMetadataEntity,
433
+ updatedValues: OpenIdConfigResponse,
434
+ fromNetwork: boolean
435
+ ): void {
436
+ authorityMetadata.authorization_endpoint =
437
+ updatedValues.authorization_endpoint;
438
+ authorityMetadata.token_endpoint = updatedValues.token_endpoint;
439
+ authorityMetadata.end_session_endpoint = updatedValues.end_session_endpoint;
440
+ authorityMetadata.issuer = updatedValues.issuer;
441
+ authorityMetadata.endpointsFromNetwork = fromNetwork;
442
+ authorityMetadata.jwks_uri = updatedValues.jwks_uri;
443
+ }
444
+
445
+ export function updateCloudDiscoveryMetadata(
446
+ authorityMetadata: AuthorityMetadataEntity,
447
+ updatedValues: CloudDiscoveryMetadata,
448
+ fromNetwork: boolean
449
+ ): void {
450
+ authorityMetadata.aliases = updatedValues.aliases;
451
+ authorityMetadata.preferred_cache = updatedValues.preferred_cache;
452
+ authorityMetadata.preferred_network = updatedValues.preferred_network;
453
+ authorityMetadata.aliasesFromNetwork = fromNetwork;
454
+ }
455
+
456
+ /**
457
+ * Returns whether or not the data needs to be refreshed
458
+ */
459
+ export function isAuthorityMetadataExpired(
460
+ metadata: AuthorityMetadataEntity
461
+ ): boolean {
462
+ return metadata.expiresAt <= TimeUtils.nowSeconds();
463
+ }