@azure/identity 3.1.0-alpha.20221101.1 → 3.1.0-alpha.20221104.2

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.

Potentially problematic release.


This version of @azure/identity might be problematic. Click here for more details.

package/dist/index.js CHANGED
@@ -512,6 +512,78 @@ function deserializeAuthenticationRecord(serializedRecord) {
512
512
  return parsed;
513
513
  }
514
514
 
515
+ // Copyright (c) Microsoft Corporation.
516
+ // Licensed under the MIT license.
517
+ function createConfigurationErrorMessage(tenantId) {
518
+ return `The current credential is not configured to acquire tokens for tenant ${tenantId}. To enable acquiring tokens for this tenant add it to the AdditionallyAllowedTenants on the credential options, or add "*" to AdditionallyAllowedTenants to allow acquiring tokens for any tenant.`;
519
+ }
520
+ /**
521
+ * Of getToken contains a tenantId, this functions allows picking this tenantId as the appropriate for authentication,
522
+ * unless multitenant authentication has been disabled through the AZURE_IDENTITY_DISABLE_MULTITENANTAUTH (on Node.js),
523
+ * or unless the original tenant Id is `adfs`.
524
+ * @internal
525
+ */
526
+ function processMultiTenantRequest(tenantId, getTokenOptions, additionallyAllowedTenantIds = []) {
527
+ var _a;
528
+ let resolvedTenantId;
529
+ if (process.env.AZURE_IDENTITY_DISABLE_MULTITENANTAUTH) {
530
+ resolvedTenantId = tenantId;
531
+ }
532
+ else if (tenantId === "adfs") {
533
+ resolvedTenantId = tenantId;
534
+ }
535
+ else {
536
+ resolvedTenantId = (_a = getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.tenantId) !== null && _a !== void 0 ? _a : tenantId;
537
+ }
538
+ if (tenantId &&
539
+ resolvedTenantId !== tenantId &&
540
+ !additionallyAllowedTenantIds.includes("*") &&
541
+ !additionallyAllowedTenantIds.some((t) => t.localeCompare(resolvedTenantId) === 0)) {
542
+ throw new Error(createConfigurationErrorMessage(tenantId));
543
+ }
544
+ return resolvedTenantId;
545
+ }
546
+
547
+ // Copyright (c) Microsoft Corporation.
548
+ /**
549
+ * @internal
550
+ */
551
+ function checkTenantId(logger, tenantId) {
552
+ if (!tenantId.match(/^[0-9a-zA-Z-.:/]+$/)) {
553
+ const error = new Error("Invalid tenant id provided. You can locate your tenant id by following the instructions listed here: https://docs.microsoft.com/partner-center/find-ids-and-domain-names.");
554
+ logger.info(formatError("", error));
555
+ throw error;
556
+ }
557
+ }
558
+ /**
559
+ * @internal
560
+ */
561
+ function resolveTenantId(logger, tenantId, clientId) {
562
+ if (tenantId) {
563
+ checkTenantId(logger, tenantId);
564
+ return tenantId;
565
+ }
566
+ if (!clientId) {
567
+ clientId = DeveloperSignOnClientId;
568
+ }
569
+ if (clientId !== DeveloperSignOnClientId) {
570
+ return "common";
571
+ }
572
+ return "organizations";
573
+ }
574
+ /**
575
+ * @internal
576
+ */
577
+ function resolveAddionallyAllowedTenantIds(additionallyAllowedTenants) {
578
+ if (!additionallyAllowedTenants || additionallyAllowedTenants.length === 0) {
579
+ return [];
580
+ }
581
+ if (additionallyAllowedTenants.includes("*")) {
582
+ return ALL_TENANTS;
583
+ }
584
+ return additionallyAllowedTenants;
585
+ }
586
+
515
587
  // Copyright (c) Microsoft Corporation.
516
588
  // Licensed under the MIT license.
517
589
  function getIdentityTokenEndpointSuffix(tenantId) {
@@ -928,78 +1000,6 @@ var RegionalAuthority;
928
1000
  RegionalAuthority["GovernmentUSDodCentral"] = "usdodcentral";
929
1001
  })(RegionalAuthority || (RegionalAuthority = {}));
930
1002
 
931
- // Copyright (c) Microsoft Corporation.
932
- // Licensed under the MIT license.
933
- function createConfigurationErrorMessage(tenantId) {
934
- return `The current credential is not configured to acquire tokens for tenant ${tenantId}. To enable acquiring tokens for this tenant add it to the AdditionallyAllowedTenants on the credential options, or add "*" to AdditionallyAllowedTenants to allow acquiring tokens for any tenant.`;
935
- }
936
- /**
937
- * Of getToken contains a tenantId, this functions allows picking this tenantId as the appropriate for authentication,
938
- * unless multitenant authentication has been disabled through the AZURE_IDENTITY_DISABLE_MULTITENANTAUTH (on Node.js),
939
- * or unless the original tenant Id is `adfs`.
940
- * @internal
941
- */
942
- function processMultiTenantRequest(tenantId, getTokenOptions, additionallyAllowedTenantIds = []) {
943
- var _a;
944
- let resolvedTenantId;
945
- if (process.env.AZURE_IDENTITY_DISABLE_MULTITENANTAUTH) {
946
- resolvedTenantId = tenantId;
947
- }
948
- else if (tenantId === "adfs") {
949
- resolvedTenantId = tenantId;
950
- }
951
- else {
952
- resolvedTenantId = (_a = getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.tenantId) !== null && _a !== void 0 ? _a : tenantId;
953
- }
954
- if (tenantId &&
955
- resolvedTenantId !== tenantId &&
956
- !additionallyAllowedTenantIds.includes("*") &&
957
- !additionallyAllowedTenantIds.some((t) => t.localeCompare(resolvedTenantId) === 0)) {
958
- throw new Error(createConfigurationErrorMessage(tenantId));
959
- }
960
- return resolvedTenantId;
961
- }
962
-
963
- // Copyright (c) Microsoft Corporation.
964
- /**
965
- * @internal
966
- */
967
- function checkTenantId(logger, tenantId) {
968
- if (!tenantId.match(/^[0-9a-zA-Z-.:/]+$/)) {
969
- const error = new Error("Invalid tenant id provided. You can locate your tenant id by following the instructions listed here: https://docs.microsoft.com/partner-center/find-ids-and-domain-names.");
970
- logger.info(formatError("", error));
971
- throw error;
972
- }
973
- }
974
- /**
975
- * @internal
976
- */
977
- function resolveTenantId(logger, tenantId, clientId) {
978
- if (tenantId) {
979
- checkTenantId(logger, tenantId);
980
- return tenantId;
981
- }
982
- if (!clientId) {
983
- clientId = DeveloperSignOnClientId;
984
- }
985
- if (clientId !== DeveloperSignOnClientId) {
986
- return "common";
987
- }
988
- return "organizations";
989
- }
990
- /**
991
- * @internal
992
- */
993
- function resolveAddionallyAllowedTenantIds(additionallyAllowedTenants) {
994
- if (!additionallyAllowedTenants || additionallyAllowedTenants.length === 0) {
995
- return [];
996
- }
997
- if (additionallyAllowedTenants.includes("*")) {
998
- return ALL_TENANTS;
999
- }
1000
- return additionallyAllowedTenants;
1001
- }
1002
-
1003
1003
  // Copyright (c) Microsoft Corporation.
1004
1004
  /**
1005
1005
  * The current persistence provider, undefined by default.
@@ -1026,20 +1026,21 @@ const msalNodeFlowCacheControl = {
1026
1026
  */
1027
1027
  class MsalNode extends MsalBaseUtilities {
1028
1028
  constructor(options) {
1029
- var _a, _b, _c;
1029
+ var _a, _b, _c, _d;
1030
1030
  super(options);
1031
1031
  this.requiresConfidential = false;
1032
1032
  this.msalConfig = this.defaultNodeMsalConfig(options);
1033
1033
  this.tenantId = resolveTenantId(options.logger, options.tenantId, options.clientId);
1034
+ this.additionallyAllowedTenantIds = resolveAddionallyAllowedTenantIds((_a = options === null || options === void 0 ? void 0 : options.tokenCredentialOptions) === null || _a === void 0 ? void 0 : _a.additionallyAllowedTenants);
1034
1035
  this.clientId = this.msalConfig.auth.clientId;
1035
1036
  if (options === null || options === void 0 ? void 0 : options.getAssertion) {
1036
1037
  this.getAssertion = options.getAssertion;
1037
1038
  }
1038
1039
  // If persistence has been configured
1039
- if (persistenceProvider !== undefined && ((_a = options.tokenCachePersistenceOptions) === null || _a === void 0 ? void 0 : _a.enabled)) {
1040
+ if (persistenceProvider !== undefined && ((_b = options.tokenCachePersistenceOptions) === null || _b === void 0 ? void 0 : _b.enabled)) {
1040
1041
  this.createCachePlugin = () => persistenceProvider(options.tokenCachePersistenceOptions);
1041
1042
  }
1042
- else if ((_b = options.tokenCachePersistenceOptions) === null || _b === void 0 ? void 0 : _b.enabled) {
1043
+ else if ((_c = options.tokenCachePersistenceOptions) === null || _c === void 0 ? void 0 : _c.enabled) {
1043
1044
  throw new Error([
1044
1045
  "Persistent token caching was requested, but no persistence provider was configured.",
1045
1046
  "You must install the identity-cache-persistence plugin package (`npm install --save @azure/identity-cache-persistence`)",
@@ -1047,7 +1048,7 @@ class MsalNode extends MsalBaseUtilities {
1047
1048
  "`useIdentityPlugin(cachePersistencePlugin)` before using `tokenCachePersistenceOptions`.",
1048
1049
  ].join(" "));
1049
1050
  }
1050
- this.azureRegion = (_c = options.regionalAuthority) !== null && _c !== void 0 ? _c : process.env.AZURE_REGIONAL_AUTHORITY_NAME;
1051
+ this.azureRegion = (_d = options.regionalAuthority) !== null && _d !== void 0 ? _d : process.env.AZURE_REGIONAL_AUTHORITY_NAME;
1051
1052
  if (this.azureRegion === RegionalAuthority.AutoDiscoverRegion) {
1052
1053
  this.azureRegion = "AUTO_DISCOVER";
1053
1054
  }
@@ -1195,7 +1196,8 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
1195
1196
  * If disableAutomaticAuthentication is sent through the constructor, it will prevent MSAL from requesting the user input.
1196
1197
  */
1197
1198
  async getToken(scopes, options = {}) {
1198
- const tenantId = processMultiTenantRequest(this.tenantId, options) || this.tenantId;
1199
+ const tenantId = processMultiTenantRequest(this.tenantId, options, this.additionallyAllowedTenantIds) ||
1200
+ this.tenantId;
1199
1201
  options.authority = getAuthority(tenantId, this.authorityHost);
1200
1202
  options.correlationId = (options === null || options === void 0 ? void 0 : options.correlationId) || this.generateUuid();
1201
1203
  await this.init(options);
@@ -3434,7 +3436,7 @@ class MsalOpenBrowser extends MsalNode {
3434
3436
  reject(new Error("Aborted"));
3435
3437
  });
3436
3438
  }
3437
- openPromise.then().catch((e) => {
3439
+ openPromise.catch((e) => {
3438
3440
  cleanup();
3439
3441
  reject(e);
3440
3442
  });