@azure/msal-common 14.1.0 → 14.2.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 (126) 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 +23 -0
  11. package/dist/authority/AuthorityMetadata.d.ts.map +1 -1
  12. package/dist/authority/AuthorityMetadata.mjs +58 -2
  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 +72 -35
  27. package/dist/cache/CacheManager.mjs.map +1 -1
  28. package/dist/cache/entities/AccessTokenEntity.mjs +1 -1
  29. package/dist/cache/entities/AccountEntity.d.ts.map +1 -1
  30. package/dist/cache/entities/AccountEntity.mjs +1 -3
  31. package/dist/cache/entities/AccountEntity.mjs.map +1 -1
  32. package/dist/cache/entities/AppMetadataEntity.mjs +1 -1
  33. package/dist/cache/entities/AuthorityMetadataEntity.mjs +1 -1
  34. package/dist/cache/entities/CacheRecord.mjs +1 -1
  35. package/dist/cache/entities/CredentialEntity.mjs +1 -1
  36. package/dist/cache/entities/IdTokenEntity.mjs +1 -1
  37. package/dist/cache/entities/RefreshTokenEntity.mjs +1 -1
  38. package/dist/cache/entities/ServerTelemetryEntity.mjs +1 -1
  39. package/dist/cache/entities/ThrottlingEntity.mjs +1 -1
  40. package/dist/cache/persistence/TokenCacheContext.mjs +1 -1
  41. package/dist/cache/utils/CacheTypes.d.ts +1 -0
  42. package/dist/cache/utils/CacheTypes.d.ts.map +1 -1
  43. package/dist/client/AuthorizationCodeClient.d.ts.map +1 -1
  44. package/dist/client/AuthorizationCodeClient.mjs +2 -2
  45. package/dist/client/AuthorizationCodeClient.mjs.map +1 -1
  46. package/dist/client/BaseClient.d.ts +1 -1
  47. package/dist/client/BaseClient.d.ts.map +1 -1
  48. package/dist/client/BaseClient.mjs +5 -4
  49. package/dist/client/BaseClient.mjs.map +1 -1
  50. package/dist/client/RefreshTokenClient.d.ts.map +1 -1
  51. package/dist/client/RefreshTokenClient.mjs +4 -4
  52. package/dist/client/RefreshTokenClient.mjs.map +1 -1
  53. package/dist/client/SilentFlowClient.d.ts +1 -0
  54. package/dist/client/SilentFlowClient.d.ts.map +1 -1
  55. package/dist/client/SilentFlowClient.mjs +20 -27
  56. package/dist/client/SilentFlowClient.mjs.map +1 -1
  57. package/dist/config/ClientConfiguration.mjs +1 -1
  58. package/dist/crypto/ICrypto.mjs +1 -1
  59. package/dist/crypto/JoseHeader.mjs +1 -1
  60. package/dist/crypto/PopTokenGenerator.mjs +1 -1
  61. package/dist/error/AuthError.mjs +1 -1
  62. package/dist/error/AuthErrorCodes.mjs +1 -1
  63. package/dist/error/ClientAuthError.d.ts +5 -0
  64. package/dist/error/ClientAuthError.d.ts.map +1 -1
  65. package/dist/error/ClientAuthError.mjs +7 -2
  66. package/dist/error/ClientAuthError.mjs.map +1 -1
  67. package/dist/error/ClientAuthErrorCodes.d.ts +1 -0
  68. package/dist/error/ClientAuthErrorCodes.d.ts.map +1 -1
  69. package/dist/error/ClientAuthErrorCodes.mjs +3 -2
  70. package/dist/error/ClientAuthErrorCodes.mjs.map +1 -1
  71. package/dist/error/ClientConfigurationError.mjs +1 -1
  72. package/dist/error/ClientConfigurationErrorCodes.mjs +1 -1
  73. package/dist/error/InteractionRequiredAuthError.mjs +1 -1
  74. package/dist/error/InteractionRequiredAuthErrorCodes.mjs +1 -1
  75. package/dist/error/JoseHeaderError.mjs +1 -1
  76. package/dist/error/JoseHeaderErrorCodes.mjs +1 -1
  77. package/dist/error/ServerError.mjs +1 -1
  78. package/dist/index.cjs +4455 -4301
  79. package/dist/index.cjs.map +1 -1
  80. package/dist/index.d.ts +2 -2
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.mjs +2 -2
  83. package/dist/logger/Logger.mjs +1 -1
  84. package/dist/network/INetworkModule.mjs +1 -1
  85. package/dist/network/NetworkManager.mjs +1 -1
  86. package/dist/network/ThrottlingUtils.mjs +1 -1
  87. package/dist/packageMetadata.d.ts +1 -1
  88. package/dist/packageMetadata.mjs +2 -2
  89. package/dist/request/AuthenticationHeaderParser.mjs +1 -1
  90. package/dist/request/RequestParameterBuilder.mjs +1 -1
  91. package/dist/request/RequestValidator.mjs +1 -1
  92. package/dist/request/ScopeSet.mjs +1 -1
  93. package/dist/response/ResponseHandler.d.ts.map +1 -1
  94. package/dist/response/ResponseHandler.mjs +8 -4
  95. package/dist/response/ResponseHandler.mjs.map +1 -1
  96. package/dist/telemetry/performance/PerformanceClient.mjs +1 -1
  97. package/dist/telemetry/performance/PerformanceEvent.d.ts +17 -1
  98. package/dist/telemetry/performance/PerformanceEvent.d.ts.map +1 -1
  99. package/dist/telemetry/performance/PerformanceEvent.mjs +9 -2
  100. package/dist/telemetry/performance/PerformanceEvent.mjs.map +1 -1
  101. package/dist/telemetry/performance/StubPerformanceClient.mjs +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/package.json +1 -1
  110. package/src/authority/Authority.ts +207 -127
  111. package/src/authority/AuthorityFactory.ts +4 -4
  112. package/src/authority/AuthorityMetadata.ts +87 -0
  113. package/src/authority/AuthorityOptions.ts +9 -0
  114. package/src/cache/CacheManager.ts +115 -52
  115. package/src/cache/entities/AccountEntity.ts +0 -3
  116. package/src/cache/utils/CacheTypes.ts +1 -0
  117. package/src/client/AuthorizationCodeClient.ts +9 -2
  118. package/src/client/BaseClient.ts +9 -6
  119. package/src/client/RefreshTokenClient.ts +17 -7
  120. package/src/client/SilentFlowClient.ts +49 -49
  121. package/src/error/ClientAuthError.ts +8 -0
  122. package/src/error/ClientAuthErrorCodes.ts +1 -0
  123. package/src/index.ts +6 -1
  124. package/src/packageMetadata.ts +1 -1
  125. package/src/response/ResponseHandler.ts +9 -3
  126. package/src/telemetry/performance/PerformanceEvent.ts +24 -2
@@ -1 +1 @@
1
- {"version":3,"file":"PerformanceEvent.mjs","sources":["../../../src/telemetry/performance/PerformanceEvent.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAKA;;;;;AAKG;AACH;AACI;;;AAGG,MAAA,iBAAA,GAAA;;AAGH;;;AAGG,IAAA,kBAAA,EAAA,oBAAA;;AAGH;;;AAGG,IAAA,0BAAA,EAAA,4BAAA;;AAGH;;;AAGG,IAAA,kBAAA,EAAA,oBAAA;;AAGH;;;AAGG,IAAA,uBAAA,EAAA,yBAAA;;AAGH;;;AAGG,IAAA,iBAAA,EAAA,mBAAA;;AAGH;;;AAGG,IAAA,gCAAA,EAAA,kCAAA;;AAGH;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,sBAAA,EAAA,wBAAA;;;;;AAUH,IAAA,6CAAA,EAAA,+CAAA;;AAEG,IAAA,uDAAA,EAAA,yDAAA;;AAGH;;AAEG;;;;AAKH;;AAEG,IAAA,0BAAA,EAAA,4BAAA;;;;;AAMH,IAAA,sBAAA,EAAA,wBAAA;;AAEG,IAAA,gCAAA,EAAA,kCAAA;;;AAIH;;AAEG,IAAA,mBAAA,EAAA,qBAAA;;AAGH;;AAEG;;;;;;;;;AAgBH,IAAA,qCAAA,EAAA,uCAAA;;AAEG,IAAA,+BAAA,EAAA,iCAAA;;;;;;;;;;;;;AAwBH,IAAA,kCAAA,EAAA,oCAAA;;AAEG,IAAA,wBAAA,EAAA,0BAAA;;;AAIH;;AAEG,IAAA,4BAAA,EAAA,8BAAA;;;;;;IAMI,oBAAA,EAAA,sBAAA;AACX,IAAA,iCACY,EAAA,mCAAiD;AAE7D,IAAA,YAAA,EAAA,cAAA;;;;;AAKG;AACH;;;;IAIW,UAAA,EAAA,CAAA;AACX,IAAA,UAAY,EAAA,CAAA;AAGZ,IAAM;;AAES,MAAA,YAAS,IAAA,GAAA,CAAA;IACtB,iBAAA;AAEF,IAAA,YAAA;;;;;AAKG,IAAA,cAAA;AACH,IAAM;AACF,IAAA,QAAA;;;;;"}
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v14.1.0 2023-10-05 */
1
+ /*! @azure/msal-common v14.2.0 2023-10-20 */
2
2
  'use strict';
3
3
  import { PerformanceEventStatus } from './PerformanceEvent.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v14.1.0 2023-10-05 */
1
+ /*! @azure/msal-common v14.2.0 2023-10-20 */
2
2
  'use strict';
3
3
  import { CacheOutcome, Constants, SERVER_TELEM_CONSTANTS, Separators } from '../../utils/Constants.mjs';
4
4
  import { AuthError } from '../../error/AuthError.mjs';
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v14.1.0 2023-10-05 */
1
+ /*! @azure/msal-common v14.2.0 2023-10-20 */
2
2
  'use strict';
3
3
  import { createClientConfigurationError } from '../error/ClientConfigurationError.mjs';
4
4
  import { createClientAuthError } from '../error/ClientAuthError.mjs';
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v14.1.0 2023-10-05 */
1
+ /*! @azure/msal-common v14.2.0 2023-10-20 */
2
2
  'use strict';
3
3
  /*
4
4
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v14.1.0 2023-10-05 */
1
+ /*! @azure/msal-common v14.2.0 2023-10-20 */
2
2
  'use strict';
3
3
  /*
4
4
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v14.1.0 2023-10-05 */
1
+ /*! @azure/msal-common v14.2.0 2023-10-20 */
2
2
  'use strict';
3
3
  import { Constants } from './Constants.mjs';
4
4
  import { createClientAuthError } from '../error/ClientAuthError.mjs';
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v14.1.0 2023-10-05 */
1
+ /*! @azure/msal-common v14.2.0 2023-10-20 */
2
2
  'use strict';
3
3
  /*
4
4
  * Copyright (c) Microsoft Corporation. All rights reserved.
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-common v14.1.0 2023-10-05 */
1
+ /*! @azure/msal-common v14.2.0 2023-10-20 */
2
2
  'use strict';
3
3
  /*
4
4
  * Copyright (c) Microsoft Corporation. All rights reserved.
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.1.0",
13
+ "version": "14.2.0",
14
14
  "description": "Microsoft Authentication Library for js",
15
15
  "keywords": [
16
16
  "implicit",
@@ -23,7 +23,8 @@ import {
23
23
  } from "../utils/Constants";
24
24
  import {
25
25
  EndpointMetadata,
26
- InstanceDiscoveryMetadata,
26
+ getCloudDiscoveryMetadataFromHardcodedValues,
27
+ getCloudDiscoveryMetadataFromNetworkResponse,
27
28
  InstanceDiscoveryMetadataAliases,
28
29
  } from "./AuthorityMetadata";
29
30
  import {
@@ -33,7 +34,11 @@ import {
33
34
  import { ProtocolMode } from "./ProtocolMode";
34
35
  import { ICacheManager } from "../cache/interface/ICacheManager";
35
36
  import { AuthorityMetadataEntity } from "../cache/entities/AuthorityMetadataEntity";
36
- import { AuthorityOptions, AzureCloudInstance } from "./AuthorityOptions";
37
+ import {
38
+ AuthorityOptions,
39
+ AzureCloudInstance,
40
+ StaticAuthorityOptions,
41
+ } from "./AuthorityOptions";
37
42
  import {
38
43
  CloudInstanceDiscoveryResponse,
39
44
  isCloudInstanceDiscoveryResponse,
@@ -393,14 +398,7 @@ export class Authority {
393
398
  this.correlationId
394
399
  );
395
400
 
396
- let metadataEntity = this.cacheManager.getAuthorityMetadataByAlias(
397
- this.hostnameAndPort
398
- );
399
-
400
- if (!metadataEntity) {
401
- metadataEntity = new AuthorityMetadataEntity();
402
- metadataEntity.updateCanonicalAuthority(this.canonicalAuthority);
403
- }
401
+ const metadataEntity = this.getCurrentMetadataEntity();
404
402
 
405
403
  const cloudDiscoverySource = await invokeAsync(
406
404
  this.updateCloudDiscoveryMetadata.bind(this),
@@ -420,10 +418,46 @@ export class Authority {
420
418
  this.performanceClient,
421
419
  this.correlationId
422
420
  )(metadataEntity);
421
+ this.updateCachedMetadata(metadataEntity, cloudDiscoverySource, {
422
+ source: endpointSource,
423
+ });
424
+ }
425
+
426
+ /**
427
+ * Returns metadata entity from cache if it exists, otherwiser returns a new metadata entity built
428
+ * from the configured canonical authority
429
+ * @returns
430
+ */
431
+ private getCurrentMetadataEntity(): AuthorityMetadataEntity {
432
+ let metadataEntity = this.cacheManager.getAuthorityMetadataByAlias(
433
+ this.hostnameAndPort
434
+ );
435
+
436
+ if (!metadataEntity) {
437
+ metadataEntity = new AuthorityMetadataEntity();
438
+ metadataEntity.updateCanonicalAuthority(this.canonicalAuthority);
439
+ }
440
+ return metadataEntity;
441
+ }
423
442
 
443
+ /**
444
+ * Updates cached metadata based on metadata source and sets the instance's metadata
445
+ * property to the same value
446
+ * @param metadataEntity
447
+ * @param cloudDiscoverySource
448
+ * @param endpointMetadataResult
449
+ */
450
+ private updateCachedMetadata(
451
+ metadataEntity: AuthorityMetadataEntity,
452
+ cloudDiscoverySource: AuthorityMetadataSource | null,
453
+ endpointMetadataResult: {
454
+ source: AuthorityMetadataSource;
455
+ metadata?: OpenIdConfigResponse;
456
+ } | null
457
+ ): void {
424
458
  if (
425
459
  cloudDiscoverySource !== AuthorityMetadataSource.CACHE &&
426
- endpointSource !== AuthorityMetadataSource.CACHE
460
+ endpointMetadataResult?.source !== AuthorityMetadataSource.CACHE
427
461
  ) {
428
462
  // Reset the expiration time unless both values came from a successful cache lookup
429
463
  metadataEntity.resetExpiresAt();
@@ -448,16 +482,95 @@ export class Authority {
448
482
  PerformanceEvents.AuthorityUpdateEndpointMetadata,
449
483
  this.correlationId
450
484
  );
485
+
486
+ const localMetadata =
487
+ this.updateEndpointMetadataFromLocalSources(metadataEntity);
488
+
489
+ // Further update may be required for hardcoded metadata if regional metadata is preferred
490
+ if (localMetadata) {
491
+ if (
492
+ localMetadata.source ===
493
+ AuthorityMetadataSource.HARDCODED_VALUES
494
+ ) {
495
+ // If the user prefers to use an azure region replace the global endpoints with regional information.
496
+ if (
497
+ this.authorityOptions.azureRegionConfiguration?.azureRegion
498
+ ) {
499
+ if (localMetadata.metadata) {
500
+ const hardcodedMetadata = await invokeAsync(
501
+ this.updateMetadataWithRegionalInformation.bind(
502
+ this
503
+ ),
504
+ PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation,
505
+ this.logger,
506
+ this.performanceClient,
507
+ this.correlationId
508
+ )(localMetadata.metadata);
509
+ metadataEntity.updateEndpointMetadata(
510
+ hardcodedMetadata,
511
+ false
512
+ );
513
+ }
514
+ }
515
+ }
516
+ return localMetadata.source;
517
+ }
518
+
519
+ // Get metadata from network if local sources aren't available
520
+ let metadata = await invokeAsync(
521
+ this.getEndpointMetadataFromNetwork.bind(this),
522
+ PerformanceEvents.AuthorityGetEndpointMetadataFromNetwork,
523
+ this.logger,
524
+ this.performanceClient,
525
+ this.correlationId
526
+ )();
527
+ if (metadata) {
528
+ // If the user prefers to use an azure region replace the global endpoints with regional information.
529
+ if (this.authorityOptions.azureRegionConfiguration?.azureRegion) {
530
+ metadata = await invokeAsync(
531
+ this.updateMetadataWithRegionalInformation.bind(this),
532
+ PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation,
533
+ this.logger,
534
+ this.performanceClient,
535
+ this.correlationId
536
+ )(metadata);
537
+ }
538
+
539
+ metadataEntity.updateEndpointMetadata(metadata, true);
540
+ return AuthorityMetadataSource.NETWORK;
541
+ } else {
542
+ // Metadata could not be obtained from the config, cache, network or hardcoded values
543
+ throw createClientAuthError(
544
+ ClientAuthErrorCodes.openIdConfigError,
545
+ this.defaultOpenIdConfigurationEndpoint
546
+ );
547
+ }
548
+ }
549
+
550
+ /**
551
+ * Updates endpoint metadata from local sources and returns where the information was retrieved from and the metadata config
552
+ * response if the source is hardcoded metadata
553
+ * @param metadataEntity
554
+ * @returns
555
+ */
556
+ private updateEndpointMetadataFromLocalSources(
557
+ metadataEntity: AuthorityMetadataEntity
558
+ ): {
559
+ source: AuthorityMetadataSource;
560
+ metadata?: OpenIdConfigResponse;
561
+ } | null {
451
562
  this.logger.verbose(
452
563
  "Attempting to get endpoint metadata from authority configuration"
453
564
  );
454
- let metadata = this.getEndpointMetadataFromConfig();
455
- if (metadata) {
565
+ const configMetadata = this.getEndpointMetadataFromConfig();
566
+ if (configMetadata) {
456
567
  this.logger.verbose(
457
568
  "Found endpoint metadata in authority configuration"
458
569
  );
459
- metadataEntity.updateEndpointMetadata(metadata, false);
460
- return AuthorityMetadataSource.CONFIG;
570
+ metadataEntity.updateEndpointMetadata(configMetadata, false);
571
+ return {
572
+ source: AuthorityMetadataSource.CONFIG,
573
+ };
461
574
  }
462
575
 
463
576
  this.logger.verbose(
@@ -470,27 +583,14 @@ export class Authority {
470
583
  "Skipping hardcoded metadata cache since skipAuthorityMetadataCache is set to true. Attempting to get endpoint metadata from the network metadata cache."
471
584
  );
472
585
  } else {
473
- let hardcodedMetadata =
586
+ const hardcodedMetadata =
474
587
  this.getEndpointMetadataFromHardcodedValues();
475
588
  if (hardcodedMetadata) {
476
- this.logger.verbose(
477
- "Found endpoint metadata from hardcoded values."
478
- );
479
- // If the user prefers to use an azure region replace the global endpoints with regional information.
480
- if (
481
- this.authorityOptions.azureRegionConfiguration?.azureRegion
482
- ) {
483
- hardcodedMetadata = await invokeAsync(
484
- this.updateMetadataWithRegionalInformation.bind(this),
485
- PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation,
486
- this.logger,
487
- this.performanceClient,
488
- this.correlationId
489
- )(hardcodedMetadata);
490
- }
491
-
492
589
  metadataEntity.updateEndpointMetadata(hardcodedMetadata, false);
493
- return AuthorityMetadataSource.HARDCODED_VALUES;
590
+ return {
591
+ source: AuthorityMetadataSource.HARDCODED_VALUES,
592
+ metadata: hardcodedMetadata,
593
+ };
494
594
  } else {
495
595
  this.logger.verbose(
496
596
  "Did not find endpoint metadata in hardcoded values... Attempting to get endpoint metadata from the network metadata cache."
@@ -507,39 +607,12 @@ export class Authority {
507
607
  ) {
508
608
  // No need to update
509
609
  this.logger.verbose("Found endpoint metadata in the cache.");
510
- return AuthorityMetadataSource.CACHE;
610
+ return { source: AuthorityMetadataSource.CACHE };
511
611
  } else if (metadataEntityExpired) {
512
612
  this.logger.verbose("The metadata entity is expired.");
513
613
  }
514
614
 
515
- metadata = await invokeAsync(
516
- this.getEndpointMetadataFromNetwork.bind(this),
517
- PerformanceEvents.AuthorityGetEndpointMetadataFromNetwork,
518
- this.logger,
519
- this.performanceClient,
520
- this.correlationId
521
- )();
522
- if (metadata) {
523
- // If the user prefers to use an azure region replace the global endpoints with regional information.
524
- if (this.authorityOptions.azureRegionConfiguration?.azureRegion) {
525
- metadata = await invokeAsync(
526
- this.updateMetadataWithRegionalInformation.bind(this),
527
- PerformanceEvents.AuthorityUpdateMetadataWithRegionalInformation,
528
- this.logger,
529
- this.performanceClient,
530
- this.correlationId
531
- )(metadata);
532
- }
533
-
534
- metadataEntity.updateEndpointMetadata(metadata, true);
535
- return AuthorityMetadataSource.NETWORK;
536
- } else {
537
- // Metadata could not be obtained from the config, cache, network or hardcoded values
538
- throw createClientAuthError(
539
- ClientAuthErrorCodes.openIdConfigError,
540
- this.defaultOpenIdConfigurationEndpoint
541
- );
542
- }
615
+ return null;
543
616
  }
544
617
 
545
618
  /**
@@ -712,6 +785,35 @@ export class Authority {
712
785
  PerformanceEvents.AuthorityUpdateCloudDiscoveryMetadata,
713
786
  this.correlationId
714
787
  );
788
+ const localMetadataSource =
789
+ this.updateCloudDiscoveryMetadataFromLocalSources(metadataEntity);
790
+ if (localMetadataSource) {
791
+ return localMetadataSource;
792
+ }
793
+
794
+ // Fallback to network as metadata source
795
+ const metadata = await invokeAsync(
796
+ this.getCloudDiscoveryMetadataFromNetwork.bind(this),
797
+ PerformanceEvents.AuthorityGetCloudDiscoveryMetadataFromNetwork,
798
+ this.logger,
799
+ this.performanceClient,
800
+ this.correlationId
801
+ )();
802
+
803
+ if (metadata) {
804
+ metadataEntity.updateCloudDiscoveryMetadata(metadata, true);
805
+ return AuthorityMetadataSource.NETWORK;
806
+ }
807
+
808
+ // Metadata could not be obtained from the config, cache, network or hardcoded values
809
+ throw createClientConfigurationError(
810
+ ClientConfigurationErrorCodes.untrustedAuthority
811
+ );
812
+ }
813
+
814
+ private updateCloudDiscoveryMetadataFromLocalSources(
815
+ metadataEntity: AuthorityMetadataEntity
816
+ ): AuthorityMetadataSource | null {
715
817
  this.logger.verbose(
716
818
  "Attempting to get cloud discovery metadata from authority configuration"
717
819
  );
@@ -732,7 +834,7 @@ export class Authority {
732
834
  metadataEntity.canonical_authority || Constants.NOT_APPLICABLE
733
835
  }`
734
836
  );
735
- let metadata = this.getCloudDiscoveryMetadataFromConfig();
837
+ const metadata = this.getCloudDiscoveryMetadataFromConfig();
736
838
  if (metadata) {
737
839
  this.logger.verbose(
738
840
  "Found cloud discovery metadata in authority configuration"
@@ -752,7 +854,9 @@ export class Authority {
752
854
  );
753
855
  } else {
754
856
  const hardcodedMetadata =
755
- this.getCloudDiscoveryMetadataFromHardcodedValues();
857
+ getCloudDiscoveryMetadataFromHardcodedValues(
858
+ this.canonicalAuthority
859
+ );
756
860
  if (hardcodedMetadata) {
757
861
  this.logger.verbose(
758
862
  "Found cloud discovery metadata from hardcoded values."
@@ -782,23 +886,7 @@ export class Authority {
782
886
  this.logger.verbose("The metadata entity is expired.");
783
887
  }
784
888
 
785
- metadata = await invokeAsync(
786
- this.getCloudDiscoveryMetadataFromNetwork.bind(this),
787
- PerformanceEvents.AuthorityGetCloudDiscoveryMetadataFromNetwork,
788
- this.logger,
789
- this.performanceClient,
790
- this.correlationId
791
- )();
792
-
793
- if (metadata) {
794
- metadataEntity.updateCloudDiscoveryMetadata(metadata, true);
795
- return AuthorityMetadataSource.NETWORK;
796
- }
797
-
798
- // Metadata could not be obtained from the config, cache, network or hardcoded values
799
- throw createClientConfigurationError(
800
- ClientConfigurationErrorCodes.untrustedAuthority
801
- );
889
+ return null;
802
890
  }
803
891
 
804
892
  /**
@@ -827,11 +915,10 @@ export class Authority {
827
915
  const parsedResponse = JSON.parse(
828
916
  this.authorityOptions.cloudDiscoveryMetadata
829
917
  ) as CloudInstanceDiscoveryResponse;
830
- const metadata =
831
- Authority.getCloudDiscoveryMetadataFromNetworkResponse(
832
- parsedResponse.metadata,
833
- this.hostnameAndPort
834
- );
918
+ const metadata = getCloudDiscoveryMetadataFromNetworkResponse(
919
+ parsedResponse.metadata,
920
+ this.hostnameAndPort
921
+ );
835
922
  this.logger.verbose("Parsed the cloud discovery metadata.");
836
923
  if (metadata) {
837
924
  this.logger.verbose(
@@ -937,7 +1024,7 @@ export class Authority {
937
1024
  this.logger.verbose(
938
1025
  "Attempting to find a match between the developer's authority and the CloudInstanceDiscoveryMetadata returned from the network request."
939
1026
  );
940
- match = Authority.getCloudDiscoveryMetadataFromNetworkResponse(
1027
+ match = getCloudDiscoveryMetadataFromNetworkResponse(
941
1028
  metadata,
942
1029
  this.hostnameAndPort
943
1030
  );
@@ -972,24 +1059,6 @@ export class Authority {
972
1059
  return match;
973
1060
  }
974
1061
 
975
- /**
976
- * Get cloud discovery metadata for common authorities
977
- */
978
- private getCloudDiscoveryMetadataFromHardcodedValues(): CloudDiscoveryMetadata | null {
979
- if (this.canonicalAuthority in InstanceDiscoveryMetadata) {
980
- const hardcodedMetadataResponse =
981
- InstanceDiscoveryMetadata[this.canonicalAuthority];
982
- const metadata =
983
- Authority.getCloudDiscoveryMetadataFromNetworkResponse(
984
- hardcodedMetadataResponse.metadata,
985
- this.hostnameAndPort
986
- );
987
- return metadata;
988
- }
989
-
990
- return null;
991
- }
992
-
993
1062
  /**
994
1063
  * Helper function to determine if this host is included in the knownAuthorities config option
995
1064
  */
@@ -1046,25 +1115,6 @@ export class Authority {
1046
1115
  };
1047
1116
  }
1048
1117
 
1049
- /**
1050
- * Searches instance discovery network response for the entry that contains the host in the aliases list
1051
- * @param response
1052
- * @param authority
1053
- */
1054
- static getCloudDiscoveryMetadataFromNetworkResponse(
1055
- response: CloudDiscoveryMetadata[],
1056
- authority: string
1057
- ): CloudDiscoveryMetadata | null {
1058
- for (let i = 0; i < response.length; i++) {
1059
- const metadata = response[i];
1060
- if (metadata.aliases.indexOf(authority) > -1) {
1061
- return metadata;
1062
- }
1063
- }
1064
-
1065
- return null;
1066
- }
1067
-
1068
1118
  /**
1069
1119
  * helper function to generate environment from authority object
1070
1120
  */
@@ -1184,9 +1234,7 @@ export class Authority {
1184
1234
  * @param authority
1185
1235
  */
1186
1236
  static transformCIAMAuthority(authority: string): string {
1187
- let ciamAuthority = authority.endsWith(Constants.FORWARD_SLASH)
1188
- ? authority
1189
- : `${authority}${Constants.FORWARD_SLASH}`;
1237
+ let ciamAuthority = authority;
1190
1238
  const authorityUrl = new UrlString(authority);
1191
1239
  const authorityUrlComponents = authorityUrl.getUrlComponents();
1192
1240
 
@@ -1205,3 +1253,35 @@ export class Authority {
1205
1253
  return ciamAuthority;
1206
1254
  }
1207
1255
  }
1256
+
1257
+ export function formatAuthorityUri(authorityUri: string): string {
1258
+ return authorityUri.endsWith(Constants.FORWARD_SLASH)
1259
+ ? authorityUri
1260
+ : `${authorityUri}${Constants.FORWARD_SLASH}`;
1261
+ }
1262
+
1263
+ export function buildStaticAuthorityOptions(
1264
+ authOptions: Partial<AuthorityOptions>
1265
+ ): StaticAuthorityOptions {
1266
+ const rawCloudDiscoveryMetadata = authOptions.cloudDiscoveryMetadata;
1267
+ let cloudDiscoveryMetadata: CloudDiscoveryMetadata[] | undefined =
1268
+ undefined;
1269
+ if (rawCloudDiscoveryMetadata) {
1270
+ try {
1271
+ cloudDiscoveryMetadata = JSON.parse(
1272
+ rawCloudDiscoveryMetadata
1273
+ ).metadata;
1274
+ } catch (e) {
1275
+ throw createClientConfigurationError(
1276
+ ClientConfigurationErrorCodes.invalidCloudDiscoveryMetadata
1277
+ );
1278
+ }
1279
+ }
1280
+ return {
1281
+ canonicalAuthority: authOptions.authority
1282
+ ? formatAuthorityUri(authOptions.authority)
1283
+ : undefined,
1284
+ knownAuthorities: authOptions.knownAuthorities,
1285
+ cloudDiscoveryMetadata: cloudDiscoveryMetadata,
1286
+ };
1287
+ }
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { Authority } from "./Authority";
6
+ import { Authority, formatAuthorityUri } from "./Authority";
7
7
  import {
8
8
  createClientConfigurationError,
9
9
  ClientConfigurationErrorCodes,
@@ -45,9 +45,9 @@ export class AuthorityFactory {
45
45
  PerformanceEvents.AuthorityFactoryCreateDiscoveredInstance,
46
46
  correlationId
47
47
  );
48
-
49
- const authorityUriFinal =
50
- Authority.transformCIAMAuthority(authorityUri);
48
+ const authorityUriFinal = Authority.transformCIAMAuthority(
49
+ formatAuthorityUri(authorityUri)
50
+ );
51
51
 
52
52
  // Initialize authority and perform discovery endpoint check.
53
53
  const acquireTokenAuthority: Authority =
@@ -3,6 +3,9 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
+ import { UrlString } from "../url/UrlString";
7
+ import { CloudDiscoveryMetadata } from "./CloudDiscoveryMetadata";
8
+
6
9
  export const rawMetdataJSON = {
7
10
  endpointMetadata: {
8
11
  "https://login.microsoftonline.com/common/": {
@@ -951,3 +954,87 @@ for (const key in InstanceDiscoveryMetadata) {
951
954
  }
952
955
  }
953
956
  }
957
+
958
+ /**
959
+ * Returns aliases for the given canonical authority if found in hardcoded Instance Discovery Metadata or null if not found
960
+ * @param canonicalAuthority
961
+ * @returns
962
+ */
963
+ export function getHardcodedAliasesForCanonicalAuthority(
964
+ canonicalAuthority?: string
965
+ ): string[] | null {
966
+ if (canonicalAuthority) {
967
+ const instanceDiscoveryMetadata =
968
+ getCloudDiscoveryMetadataFromHardcodedValues(canonicalAuthority);
969
+ if (instanceDiscoveryMetadata) {
970
+ return instanceDiscoveryMetadata.aliases;
971
+ }
972
+ }
973
+ return null;
974
+ }
975
+
976
+ /**
977
+ * Returns aliases for from the raw cloud discovery metadata given in configuration or null if no configuration was provided
978
+ * @param rawCloudDiscoveryMetadata
979
+ * @returns
980
+ */
981
+ export function getAliasesFromConfigMetadata(
982
+ canonicalAuthority?: string,
983
+ cloudDiscoveryMetadata?: CloudDiscoveryMetadata[]
984
+ ): string[] | null {
985
+ if (canonicalAuthority && cloudDiscoveryMetadata) {
986
+ const canonicalAuthorityUrlComponents = new UrlString(
987
+ canonicalAuthority
988
+ ).getUrlComponents();
989
+ const metadata = getCloudDiscoveryMetadataFromNetworkResponse(
990
+ cloudDiscoveryMetadata,
991
+ canonicalAuthorityUrlComponents.HostNameAndPort
992
+ );
993
+
994
+ if (metadata) {
995
+ return metadata.aliases;
996
+ }
997
+ }
998
+
999
+ return null;
1000
+ }
1001
+
1002
+ /**
1003
+ * Searches instance discovery network response for the entry that contains the host in the aliases list
1004
+ * @param response
1005
+ * @param authority
1006
+ */
1007
+ export function getCloudDiscoveryMetadataFromNetworkResponse(
1008
+ response: CloudDiscoveryMetadata[],
1009
+ authority: string
1010
+ ): CloudDiscoveryMetadata | null {
1011
+ for (let i = 0; i < response.length; i++) {
1012
+ const metadata = response[i];
1013
+ if (metadata.aliases.includes(authority)) {
1014
+ return metadata;
1015
+ }
1016
+ }
1017
+
1018
+ return null;
1019
+ }
1020
+
1021
+ /**
1022
+ * Get cloud discovery metadata for common authorities
1023
+ */
1024
+ export function getCloudDiscoveryMetadataFromHardcodedValues(
1025
+ canonicalAuthority: string
1026
+ ): CloudDiscoveryMetadata | null {
1027
+ const canonicalAuthorityUrlComponents = new UrlString(
1028
+ canonicalAuthority
1029
+ ).getUrlComponents();
1030
+
1031
+ if (canonicalAuthority in InstanceDiscoveryMetadata) {
1032
+ const metadata = getCloudDiscoveryMetadataFromNetworkResponse(
1033
+ InstanceDiscoveryMetadata[canonicalAuthority].metadata,
1034
+ canonicalAuthorityUrlComponents.HostNameAndPort
1035
+ );
1036
+ return metadata;
1037
+ }
1038
+
1039
+ return null;
1040
+ }
@@ -6,6 +6,7 @@
6
6
  import { ProtocolMode } from "./ProtocolMode";
7
7
  import { OIDCOptions } from "./OIDCOptions";
8
8
  import { AzureRegionConfiguration } from "./AzureRegionConfiguration";
9
+ import { CloudDiscoveryMetadata } from "./CloudDiscoveryMetadata";
9
10
 
10
11
  export type AuthorityOptions = {
11
12
  protocolMode: ProtocolMode;
@@ -15,6 +16,14 @@ export type AuthorityOptions = {
15
16
  authorityMetadata: string;
16
17
  skipAuthorityMetadataCache?: boolean;
17
18
  azureRegionConfiguration?: AzureRegionConfiguration;
19
+ authority?: string;
20
+ };
21
+
22
+ export type StaticAuthorityOptions = Partial<
23
+ Pick<AuthorityOptions, "knownAuthorities">
24
+ > & {
25
+ canonicalAuthority?: string;
26
+ cloudDiscoveryMetadata?: CloudDiscoveryMetadata[];
18
27
  };
19
28
 
20
29
  export const AzureCloudInstance = {