@azure/identity 2.0.0-beta.6 → 2.0.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.
Potentially problematic release.
This version of @azure/identity might be problematic. Click here for more details.
- package/CHANGELOG.md +131 -3
- package/README.md +51 -3
- package/dist/index.js +207 -218
- package/dist/index.js.map +1 -1
- package/dist-esm/src/client/identityClient.js +2 -2
- package/dist-esm/src/client/identityClient.js.map +1 -1
- package/dist-esm/src/credentials/authorizationCodeCredential.browser.js +1 -1
- package/dist-esm/src/credentials/authorizationCodeCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/{applicationCredential.browser.js → azureApplicationCredential.browser.js} +9 -4
- package/dist-esm/src/credentials/azureApplicationCredential.browser.js.map +1 -0
- package/dist-esm/src/credentials/azureApplicationCredential.js +36 -0
- package/dist-esm/src/credentials/azureApplicationCredential.js.map +1 -0
- package/dist-esm/src/credentials/azureCliCredential.browser.js +7 -0
- package/dist-esm/src/credentials/azureCliCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/azureCliCredential.js +9 -9
- package/dist-esm/src/credentials/azureCliCredential.js.map +1 -1
- package/dist-esm/src/credentials/azurePowerShellCredential.browser.js +3 -1
- package/dist-esm/src/credentials/azurePowerShellCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/azurePowerShellCredential.js +13 -13
- package/dist-esm/src/credentials/azurePowerShellCredential.js.map +1 -1
- package/dist-esm/src/credentials/chainedTokenCredential.js +2 -2
- package/dist-esm/src/credentials/chainedTokenCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientCertificateCredential.browser.js +7 -0
- package/dist-esm/src/credentials/clientCertificateCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/clientCertificateCredential.js +18 -15
- package/dist-esm/src/credentials/clientCertificateCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientCertificateCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/clientSecretCredential.browser.js +1 -1
- package/dist-esm/src/credentials/clientSecretCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/clientSecretCredential.js +1 -1
- package/dist-esm/src/credentials/clientSecretCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientSecretCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/defaultAzureCredential.js +16 -12
- package/dist-esm/src/credentials/defaultAzureCredential.js.map +1 -1
- package/dist-esm/src/credentials/deviceCodeCredential.browser.js +7 -0
- package/dist-esm/src/credentials/deviceCodeCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/deviceCodeCredential.js +14 -0
- package/dist-esm/src/credentials/deviceCodeCredential.js.map +1 -1
- package/dist-esm/src/credentials/environmentCredential.browser.js +7 -0
- package/dist-esm/src/credentials/environmentCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/environmentCredential.js +5 -21
- package/dist-esm/src/credentials/environmentCredential.js.map +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js +7 -7
- package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredential.js +7 -7
- package/dist-esm/src/credentials/interactiveBrowserCredential.js.map +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/arcMsi.js +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/arcMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js +32 -23
- package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/index.js +2 -2
- package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
- package/dist-esm/src/credentials/onBehalfOfCredential.browser.js +6 -0
- package/dist-esm/src/credentials/onBehalfOfCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/onBehalfOfCredential.js +6 -11
- package/dist-esm/src/credentials/onBehalfOfCredential.js.map +1 -1
- package/dist-esm/src/credentials/onBehalfOfCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/usernamePasswordCredential.browser.js +1 -1
- package/dist-esm/src/credentials/usernamePasswordCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/usernamePasswordCredential.js +1 -3
- package/dist-esm/src/credentials/usernamePasswordCredential.js.map +1 -1
- package/dist-esm/src/credentials/visualStudioCodeCredential.browser.js +6 -0
- package/dist-esm/src/credentials/visualStudioCodeCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/visualStudioCodeCredential.js +5 -7
- package/dist-esm/src/credentials/visualStudioCodeCredential.js.map +1 -1
- package/dist-esm/src/{client/errors.js → errors.js} +15 -0
- package/dist-esm/src/errors.js.map +1 -0
- package/dist-esm/src/index.js +1 -4
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/msal/browserFlows/browserCommon.js +8 -7
- package/dist-esm/src/msal/browserFlows/browserCommon.js.map +1 -1
- package/dist-esm/src/msal/browserFlows/msalAuthCode.js +12 -4
- package/dist-esm/src/msal/browserFlows/msalAuthCode.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalAuthorizationCode.js +1 -1
- package/dist-esm/src/msal/nodeFlows/msalAuthorizationCode.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalClientCertificate.js +6 -5
- package/dist-esm/src/msal/nodeFlows/msalClientCertificate.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalOnBehalfOf.js +1 -1
- package/dist-esm/src/msal/nodeFlows/msalOnBehalfOf.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js +1 -1
- package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/nodeCommon.js +13 -7
- package/dist-esm/src/msal/nodeFlows/nodeCommon.js.map +1 -1
- package/dist-esm/src/msal/utils.js +7 -4
- package/dist-esm/src/msal/utils.js.map +1 -1
- package/dist-esm/src/util/tracing.js +1 -1
- package/dist-esm/src/util/tracing.js.map +1 -1
- package/dist-esm/src/util/validateMultiTenant.browser.js +22 -0
- package/dist-esm/src/util/validateMultiTenant.browser.js.map +1 -0
- package/dist-esm/src/util/validateMultiTenant.js +17 -12
- package/dist-esm/src/util/validateMultiTenant.js.map +1 -1
- package/package.json +7 -5
- package/types/identity.d.ts +133 -233
- package/dist-esm/src/client/errors.js.map +0 -1
- package/dist-esm/src/credentials/applicationCredential.browser.js.map +0 -1
- package/dist-esm/src/credentials/applicationCredential.js +0 -34
- package/dist-esm/src/credentials/applicationCredential.js.map +0 -1
- package/dist-esm/src/msal/errors.js +0 -22
- package/dist-esm/src/msal/errors.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -18,6 +18,7 @@ var fs__default = _interopDefault(fs);
|
|
|
18
18
|
var os = _interopDefault(require('os'));
|
|
19
19
|
var path = _interopDefault(require('path'));
|
|
20
20
|
var child_process = require('child_process');
|
|
21
|
+
var child_process__default = _interopDefault(child_process);
|
|
21
22
|
var crypto = require('crypto');
|
|
22
23
|
var util = require('util');
|
|
23
24
|
var http = _interopDefault(require('http'));
|
|
@@ -165,6 +166,21 @@ function convertOAuthErrorResponseToErrorResponse(errorBody) {
|
|
|
165
166
|
traceId: errorBody.trace_id
|
|
166
167
|
};
|
|
167
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Error used to enforce authentication after trying to retrieve a token silently.
|
|
171
|
+
*/
|
|
172
|
+
class AuthenticationRequiredError extends Error {
|
|
173
|
+
constructor(
|
|
174
|
+
/**
|
|
175
|
+
* Optional parameters. A message can be specified. The {@link GetTokenOptions} of the request can also be specified to more easily associate the error with the received parameters.
|
|
176
|
+
*/
|
|
177
|
+
options) {
|
|
178
|
+
super(options.message);
|
|
179
|
+
this.scopes = options.scopes;
|
|
180
|
+
this.getTokenOptions = options.getTokenOptions;
|
|
181
|
+
this.name = "AuthenticationRequiredError";
|
|
182
|
+
}
|
|
183
|
+
}
|
|
168
184
|
|
|
169
185
|
// Copyright (c) Microsoft Corporation.
|
|
170
186
|
// Licensed under the MIT license.
|
|
@@ -183,7 +199,7 @@ function getIdentityTokenEndpointSuffix(tenantId) {
|
|
|
183
199
|
* @internal
|
|
184
200
|
*/
|
|
185
201
|
const createSpan = coreTracing.createSpanFunction({
|
|
186
|
-
packagePrefix: "
|
|
202
|
+
packagePrefix: "",
|
|
187
203
|
namespace: "Microsoft.AAD"
|
|
188
204
|
});
|
|
189
205
|
/**
|
|
@@ -315,7 +331,7 @@ function getIdentityClientAuthorityHost(options) {
|
|
|
315
331
|
class IdentityClient extends coreClient.ServiceClient {
|
|
316
332
|
constructor(options) {
|
|
317
333
|
var _a;
|
|
318
|
-
const packageDetails = `azsdk-js-identity/2.0.0
|
|
334
|
+
const packageDetails = `azsdk-js-identity/2.0.0`;
|
|
319
335
|
const userAgentPrefix = ((_a = options === null || options === void 0 ? void 0 : options.userAgentOptions) === null || _a === void 0 ? void 0 : _a.userAgentPrefix)
|
|
320
336
|
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
|
|
321
337
|
: `${packageDetails}`;
|
|
@@ -511,28 +527,6 @@ function resolveTenantId(logger, tenantId, clientId) {
|
|
|
511
527
|
return "organizations";
|
|
512
528
|
}
|
|
513
529
|
|
|
514
|
-
// Copyright (c) Microsoft Corporation.
|
|
515
|
-
// Licensed under the MIT license.
|
|
516
|
-
/**
|
|
517
|
-
* Error used to enforce authentication after trying to retrieve a token silently.
|
|
518
|
-
*/
|
|
519
|
-
class AuthenticationRequiredError extends Error {
|
|
520
|
-
constructor(
|
|
521
|
-
/**
|
|
522
|
-
* The list of scopes for which the token will have access.
|
|
523
|
-
*/
|
|
524
|
-
scopes,
|
|
525
|
-
/**
|
|
526
|
-
* The options used to configure the getToken request.
|
|
527
|
-
*/
|
|
528
|
-
getTokenOptions = {}, message) {
|
|
529
|
-
super(message);
|
|
530
|
-
this.scopes = scopes;
|
|
531
|
-
this.getTokenOptions = getTokenOptions;
|
|
532
|
-
this.name = "AuthenticationRequiredError";
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
|
|
536
530
|
// Copyright (c) Microsoft Corporation.
|
|
537
531
|
/**
|
|
538
532
|
* Latest AuthenticationRecord version
|
|
@@ -546,7 +540,11 @@ const LatestAuthenticationRecordVersion = "1.0";
|
|
|
546
540
|
function ensureValidMsalToken(scopes, logger, msalToken, getTokenOptions) {
|
|
547
541
|
const error = (message) => {
|
|
548
542
|
logger.getToken.info(message);
|
|
549
|
-
return new AuthenticationRequiredError(
|
|
543
|
+
return new AuthenticationRequiredError({
|
|
544
|
+
scopes: Array.isArray(scopes) ? scopes : [scopes],
|
|
545
|
+
getTokenOptions,
|
|
546
|
+
message
|
|
547
|
+
});
|
|
550
548
|
};
|
|
551
549
|
if (!msalToken) {
|
|
552
550
|
throw error("No response");
|
|
@@ -674,7 +672,7 @@ class MsalBaseUtilities {
|
|
|
674
672
|
error.name === "AbortError") {
|
|
675
673
|
return error;
|
|
676
674
|
}
|
|
677
|
-
return new AuthenticationRequiredError(scopes, getTokenOptions, error.message);
|
|
675
|
+
return new AuthenticationRequiredError({ scopes, getTokenOptions, message: error.message });
|
|
678
676
|
}
|
|
679
677
|
}
|
|
680
678
|
// transformations.ts
|
|
@@ -738,6 +736,40 @@ function deserializeAuthenticationRecord(serializedRecord) {
|
|
|
738
736
|
}
|
|
739
737
|
|
|
740
738
|
// Copyright (c) Microsoft Corporation.
|
|
739
|
+
// Licensed under the MIT license.
|
|
740
|
+
/**
|
|
741
|
+
* @internal
|
|
742
|
+
*/
|
|
743
|
+
const multiTenantDisabledErrorMessage = "A getToken request was attempted with a tenant different than the tenant configured at the initialization of the credential, but multi-tenant authentication has been disabled by the environment variable AZURE_IDENTITY_DISABLE_MULTITENANTAUTH.";
|
|
744
|
+
/**
|
|
745
|
+
* @internal
|
|
746
|
+
*/
|
|
747
|
+
const multiTenantADFSErrorMessage = "A new tenant Id can't be assigned through the GetTokenOptions when a credential has been originally configured to use the tenant `adfs`.";
|
|
748
|
+
/**
|
|
749
|
+
* Of getToken contains a tenantId, this functions allows picking this tenantId as the appropriate for authentication,
|
|
750
|
+
* unless multitenant authentication has been disabled through the AZURE_IDENTITY_DISABLE_MULTITENANTAUTH (on Node.js),
|
|
751
|
+
* or unless the original tenant Id is `adfs`.
|
|
752
|
+
* @internal
|
|
753
|
+
*/
|
|
754
|
+
function processMultiTenantRequest(tenantId, getTokenOptions) {
|
|
755
|
+
if (!(getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.tenantId)) {
|
|
756
|
+
return tenantId;
|
|
757
|
+
}
|
|
758
|
+
if (process.env.AZURE_IDENTITY_DISABLE_MULTITENANTAUTH) {
|
|
759
|
+
throw new Error(multiTenantDisabledErrorMessage);
|
|
760
|
+
}
|
|
761
|
+
if (tenantId === "adfs") {
|
|
762
|
+
throw new Error(multiTenantADFSErrorMessage);
|
|
763
|
+
}
|
|
764
|
+
return getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.tenantId;
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// Copyright (c) Microsoft Corporation.
|
|
768
|
+
// Licensed under the MIT license.
|
|
769
|
+
/**
|
|
770
|
+
* Helps specify a regional authority, or "AutoDiscoverRegion" to auto-detect the region.
|
|
771
|
+
*/
|
|
772
|
+
var RegionalAuthority;
|
|
741
773
|
(function (RegionalAuthority) {
|
|
742
774
|
/** Instructs MSAL to attempt to discover the region */
|
|
743
775
|
RegionalAuthority["AutoDiscoverRegion"] = "AutoDiscoverRegion";
|
|
@@ -845,31 +877,7 @@ function deserializeAuthenticationRecord(serializedRecord) {
|
|
|
845
877
|
RegionalAuthority["GovernmentUSDodEast"] = "usdodeast";
|
|
846
878
|
/** Uses the {@link RegionalAuthority} for the Azure 'usdodcentral' region. */
|
|
847
879
|
RegionalAuthority["GovernmentUSDodCentral"] = "usdodcentral";
|
|
848
|
-
})(
|
|
849
|
-
|
|
850
|
-
// Copyright (c) Microsoft Corporation.
|
|
851
|
-
// Licensed under the MIT license.
|
|
852
|
-
/**
|
|
853
|
-
* @internal
|
|
854
|
-
*/
|
|
855
|
-
const multiTenantErrorMessage = "A getToken request was attempted with a tenant different than the tenant configured at the initialization of the credential, but multi-tenant authentication was not enabled in this credential instance.";
|
|
856
|
-
/**
|
|
857
|
-
* Verifies whether locally assigned tenants are equal to tenants received through getToken.
|
|
858
|
-
* Returns the appropriate tenant.
|
|
859
|
-
* @internal
|
|
860
|
-
*/
|
|
861
|
-
function processMultiTenantRequest(tenantId, allowMultiTenantAuthentication, getTokenOptions) {
|
|
862
|
-
if (!allowMultiTenantAuthentication &&
|
|
863
|
-
(getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.tenantId) &&
|
|
864
|
-
tenantId &&
|
|
865
|
-
getTokenOptions.tenantId !== tenantId) {
|
|
866
|
-
throw new Error(multiTenantErrorMessage);
|
|
867
|
-
}
|
|
868
|
-
if (allowMultiTenantAuthentication && (getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.tenantId)) {
|
|
869
|
-
return getTokenOptions.tenantId;
|
|
870
|
-
}
|
|
871
|
-
return tenantId;
|
|
872
|
-
}
|
|
880
|
+
})(RegionalAuthority || (RegionalAuthority = {}));
|
|
873
881
|
|
|
874
882
|
// Copyright (c) Microsoft Corporation.
|
|
875
883
|
/**
|
|
@@ -902,7 +910,6 @@ class MsalNode extends MsalBaseUtilities {
|
|
|
902
910
|
this.requiresConfidential = false;
|
|
903
911
|
this.msalConfig = this.defaultNodeMsalConfig(options);
|
|
904
912
|
this.tenantId = resolveTenantId(options.logger, options.tenantId, options.clientId);
|
|
905
|
-
this.allowMultiTenantAuthentication = options === null || options === void 0 ? void 0 : options.allowMultiTenantAuthentication;
|
|
906
913
|
this.clientId = this.msalConfig.auth.clientId;
|
|
907
914
|
// If persistence has been configured
|
|
908
915
|
if (persistenceProvider !== undefined && ((_a = options.tokenCachePersistenceOptions) === null || _a === void 0 ? void 0 : _a.enabled)) {
|
|
@@ -917,7 +924,7 @@ class MsalNode extends MsalBaseUtilities {
|
|
|
917
924
|
].join(" "));
|
|
918
925
|
}
|
|
919
926
|
this.azureRegion = (_c = options.regionalAuthority) !== null && _c !== void 0 ? _c : process.env.AZURE_REGIONAL_AUTHORITY_NAME;
|
|
920
|
-
if (this.azureRegion ===
|
|
927
|
+
if (this.azureRegion === RegionalAuthority.AutoDiscoverRegion) {
|
|
921
928
|
this.azureRegion = "AUTO_DISCOVER";
|
|
922
929
|
}
|
|
923
930
|
}
|
|
@@ -1033,7 +1040,11 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
|
1033
1040
|
var _a, _b;
|
|
1034
1041
|
await this.getActiveAccount();
|
|
1035
1042
|
if (!this.account) {
|
|
1036
|
-
throw new AuthenticationRequiredError(
|
|
1043
|
+
throw new AuthenticationRequiredError({
|
|
1044
|
+
scopes,
|
|
1045
|
+
getTokenOptions: options,
|
|
1046
|
+
message: "Silent authentication failed. We couldn't retrieve an active account from the cache."
|
|
1047
|
+
});
|
|
1037
1048
|
}
|
|
1038
1049
|
const silentRequest = {
|
|
1039
1050
|
// To be able to re-use the account, the Token Cache must also have been provided.
|
|
@@ -1056,8 +1067,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
|
1056
1067
|
* If disableAutomaticAuthentication is sent through the constructor, it will prevent MSAL from requesting the user input.
|
|
1057
1068
|
*/
|
|
1058
1069
|
async getToken(scopes, options = {}) {
|
|
1059
|
-
const tenantId = processMultiTenantRequest(this.tenantId,
|
|
1060
|
-
this.tenantId;
|
|
1070
|
+
const tenantId = processMultiTenantRequest(this.tenantId, options) || this.tenantId;
|
|
1061
1071
|
options.authority = getAuthority(tenantId, this.authorityHost);
|
|
1062
1072
|
options.correlationId = (options === null || options === void 0 ? void 0 : options.correlationId) || this.generateUuid();
|
|
1063
1073
|
await this.init(options);
|
|
@@ -1069,7 +1079,11 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
|
1069
1079
|
throw err;
|
|
1070
1080
|
}
|
|
1071
1081
|
if (options === null || options === void 0 ? void 0 : options.disableAutomaticAuthentication) {
|
|
1072
|
-
throw new AuthenticationRequiredError(
|
|
1082
|
+
throw new AuthenticationRequiredError({
|
|
1083
|
+
scopes,
|
|
1084
|
+
getTokenOptions: options,
|
|
1085
|
+
message: "Automatic authentication has been disabled. You may call the authentication() method."
|
|
1086
|
+
});
|
|
1073
1087
|
}
|
|
1074
1088
|
this.logger.info(`Silent authentication failed, falling back to interactive method.`);
|
|
1075
1089
|
return this.doGetToken(scopes, options);
|
|
@@ -1138,7 +1152,7 @@ function getPropertyFromVSCode(property) {
|
|
|
1138
1152
|
}
|
|
1139
1153
|
}
|
|
1140
1154
|
/**
|
|
1141
|
-
*
|
|
1155
|
+
* Connects to Azure using the credential provided by the VSCode extension 'Azure Account'.
|
|
1142
1156
|
* Once the user has logged in via the extension, this credential can share the same refresh token
|
|
1143
1157
|
* that is cached by the extension.
|
|
1144
1158
|
*/
|
|
@@ -1167,7 +1181,6 @@ class VisualStudioCodeCredential {
|
|
|
1167
1181
|
else {
|
|
1168
1182
|
this.tenantId = CommonTenantId;
|
|
1169
1183
|
}
|
|
1170
|
-
this.allowMultiTenantAuthentication = options === null || options === void 0 ? void 0 : options.allowMultiTenantAuthentication;
|
|
1171
1184
|
checkUnsupportedTenant(this.tenantId);
|
|
1172
1185
|
}
|
|
1173
1186
|
/**
|
|
@@ -1201,8 +1214,7 @@ class VisualStudioCodeCredential {
|
|
|
1201
1214
|
async getToken(scopes, options) {
|
|
1202
1215
|
var _a, _b;
|
|
1203
1216
|
await this.prepareOnce();
|
|
1204
|
-
const tenantId = processMultiTenantRequest(this.tenantId,
|
|
1205
|
-
this.tenantId;
|
|
1217
|
+
const tenantId = processMultiTenantRequest(this.tenantId, options) || this.tenantId;
|
|
1206
1218
|
if (findCredentials === undefined) {
|
|
1207
1219
|
throw new CredentialUnavailableError([
|
|
1208
1220
|
"No implementation of `VisualStudioCodeCredential` is available.",
|
|
@@ -1239,13 +1251,13 @@ class VisualStudioCodeCredential {
|
|
|
1239
1251
|
return tokenResponse.accessToken;
|
|
1240
1252
|
}
|
|
1241
1253
|
else {
|
|
1242
|
-
const error = new CredentialUnavailableError("Could not retrieve the token associated with Visual Studio Code. Have you connected using the 'Azure Account' extension recently?");
|
|
1254
|
+
const error = new CredentialUnavailableError("Could not retrieve the token associated with Visual Studio Code. Have you connected using the 'Azure Account' extension recently? To troubleshoot, visit https://aka.ms/azsdk/js/identity/visualstudiocodecredential/troubleshoot.");
|
|
1243
1255
|
logger$1.getToken.info(formatError(scopes, error));
|
|
1244
1256
|
throw error;
|
|
1245
1257
|
}
|
|
1246
1258
|
}
|
|
1247
1259
|
else {
|
|
1248
|
-
const error = new CredentialUnavailableError("Could not retrieve the token associated with Visual Studio Code. Did you connect using the 'Azure Account' extension?");
|
|
1260
|
+
const error = new CredentialUnavailableError("Could not retrieve the token associated with Visual Studio Code. Did you connect using the 'Azure Account' extension? To troubleshoot, visit https://aka.ms/azsdk/js/identity/visualstudiocodecredential/troubleshoot.");
|
|
1249
1261
|
logger$1.getToken.info(formatError(scopes, error));
|
|
1250
1262
|
throw error;
|
|
1251
1263
|
}
|
|
@@ -1340,7 +1352,7 @@ class ChainedTokenCredential {
|
|
|
1340
1352
|
let token = null;
|
|
1341
1353
|
let successfulCredentialName = "";
|
|
1342
1354
|
const errors = [];
|
|
1343
|
-
const { span, updatedOptions } = createSpan("ChainedTokenCredential
|
|
1355
|
+
const { span, updatedOptions } = createSpan("ChainedTokenCredential.getToken", options);
|
|
1344
1356
|
for (let i = 0; i < this._sources.length && token === null; i++) {
|
|
1345
1357
|
try {
|
|
1346
1358
|
token = await this._sources[i].getToken(scopes, updatedOptions);
|
|
@@ -1427,14 +1439,14 @@ const cliCredentialInternals = {
|
|
|
1427
1439
|
}
|
|
1428
1440
|
return new Promise((resolve, reject) => {
|
|
1429
1441
|
try {
|
|
1430
|
-
|
|
1442
|
+
child_process__default.execFile("az", [
|
|
1431
1443
|
"account",
|
|
1432
1444
|
"get-access-token",
|
|
1433
1445
|
"--output",
|
|
1434
1446
|
"json",
|
|
1435
1447
|
"--resource",
|
|
1436
|
-
|
|
1437
|
-
|
|
1448
|
+
resource,
|
|
1449
|
+
...tenantSection
|
|
1438
1450
|
], { cwd: cliCredentialInternals.getSafeWorkingDir() }, (error, stdout, stderr) => {
|
|
1439
1451
|
resolve({ stdout: stdout, stderr: stderr, error });
|
|
1440
1452
|
});
|
|
@@ -1451,18 +1463,18 @@ const logger$3 = credentialLogger("AzureCliCredential");
|
|
|
1451
1463
|
* via the Azure CLI ('az') commandline tool.
|
|
1452
1464
|
* To do so, it will read the user access token and expire time
|
|
1453
1465
|
* with Azure CLI command "az account get-access-token".
|
|
1454
|
-
* To be able to use this credential, ensure that you have already logged
|
|
1455
|
-
* in via the 'az' tool using the command "az login" from the commandline.
|
|
1456
1466
|
*/
|
|
1457
1467
|
class AzureCliCredential {
|
|
1458
1468
|
/**
|
|
1459
1469
|
* Creates an instance of the {@link AzureCliCredential}.
|
|
1460
1470
|
*
|
|
1471
|
+
* To use this credential, ensure that you have already logged
|
|
1472
|
+
* in via the 'az' tool using the command "az login" from the commandline.
|
|
1473
|
+
*
|
|
1461
1474
|
* @param options - Options, to optionally allow multi-tenant requests.
|
|
1462
1475
|
*/
|
|
1463
1476
|
constructor(options) {
|
|
1464
1477
|
this.tenantId = options === null || options === void 0 ? void 0 : options.tenantId;
|
|
1465
|
-
this.allowMultiTenantAuthentication = options === null || options === void 0 ? void 0 : options.allowMultiTenantAuthentication;
|
|
1466
1478
|
}
|
|
1467
1479
|
/**
|
|
1468
1480
|
* Authenticates with Azure Active Directory and returns an access token if successful.
|
|
@@ -1473,7 +1485,7 @@ class AzureCliCredential {
|
|
|
1473
1485
|
* TokenCredential implementation might make.
|
|
1474
1486
|
*/
|
|
1475
1487
|
async getToken(scopes, options) {
|
|
1476
|
-
const tenantId = processMultiTenantRequest(this.tenantId,
|
|
1488
|
+
const tenantId = processMultiTenantRequest(this.tenantId, options);
|
|
1477
1489
|
if (tenantId) {
|
|
1478
1490
|
checkTenantId(logger$3, tenantId);
|
|
1479
1491
|
}
|
|
@@ -1482,7 +1494,7 @@ class AzureCliCredential {
|
|
|
1482
1494
|
ensureValidScope(scope, logger$3);
|
|
1483
1495
|
const resource = getScopeResource(scope);
|
|
1484
1496
|
let responseData = "";
|
|
1485
|
-
const { span } = createSpan("AzureCliCredential
|
|
1497
|
+
const { span } = createSpan("AzureCliCredential.getToken", options);
|
|
1486
1498
|
try {
|
|
1487
1499
|
const obj = await cliCredentialInternals.getAzureCliAccessToken(resource, tenantId);
|
|
1488
1500
|
if (obj.stderr) {
|
|
@@ -1599,7 +1611,8 @@ const powerShellErrors = {
|
|
|
1599
1611
|
*/
|
|
1600
1612
|
const powerShellPublicErrorMessages = {
|
|
1601
1613
|
login: "Please run 'Connect-AzAccount' from PowerShell to authenticate before using this credential.",
|
|
1602
|
-
installed: `The 'Az.Account' module >= 2.2.0 is not installed. Install the Azure Az PowerShell module with: "Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force"
|
|
1614
|
+
installed: `The 'Az.Account' module >= 2.2.0 is not installed. Install the Azure Az PowerShell module with: "Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force".`,
|
|
1615
|
+
troubleshoot: `To troubleshoot, visit https://aka.ms/azsdk/js/identity/powershellcredential/troubleshoot.`
|
|
1603
1616
|
};
|
|
1604
1617
|
// PowerShell Azure User not logged in error check.
|
|
1605
1618
|
const isLoginError = (err) => err.message.match(`(.*)${powerShellErrors.login}(.*)`);
|
|
@@ -1618,22 +1631,21 @@ if (isWindows) {
|
|
|
1618
1631
|
* This credential will use the currently logged-in user information from the
|
|
1619
1632
|
* Azure PowerShell module. To do so, it will read the user access token and
|
|
1620
1633
|
* expire time with Azure PowerShell command `Get-AzAccessToken -ResourceUrl {ResourceScope}`
|
|
1621
|
-
*
|
|
1622
|
-
* To be able to use this credential:
|
|
1623
|
-
* - Install the Azure Az PowerShell module with:
|
|
1624
|
-
* `Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force`.
|
|
1625
|
-
* - You have already logged in to Azure PowerShell using the command
|
|
1626
|
-
* `Connect-AzAccount` from the command line.
|
|
1627
1634
|
*/
|
|
1628
1635
|
class AzurePowerShellCredential {
|
|
1629
1636
|
/**
|
|
1630
|
-
* Creates an instance of the {@link
|
|
1637
|
+
* Creates an instance of the {@link AzurePowerShellCredential}.
|
|
1638
|
+
*
|
|
1639
|
+
* To use this credential:
|
|
1640
|
+
* - Install the Azure Az PowerShell module with:
|
|
1641
|
+
* `Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force`.
|
|
1642
|
+
* - You have already logged in to Azure PowerShell using the command
|
|
1643
|
+
* `Connect-AzAccount` from the command line.
|
|
1631
1644
|
*
|
|
1632
1645
|
* @param options - Options, to optionally allow multi-tenant requests.
|
|
1633
1646
|
*/
|
|
1634
1647
|
constructor(options) {
|
|
1635
1648
|
this.tenantId = options === null || options === void 0 ? void 0 : options.tenantId;
|
|
1636
|
-
this.allowMultiTenantAuthentication = options === null || options === void 0 ? void 0 : options.allowMultiTenantAuthentication;
|
|
1637
1649
|
}
|
|
1638
1650
|
/**
|
|
1639
1651
|
* Gets the access token from Azure PowerShell
|
|
@@ -1674,7 +1686,7 @@ class AzurePowerShellCredential {
|
|
|
1674
1686
|
throw new Error(`Unable to parse the output of PowerShell. Received output: ${result}`);
|
|
1675
1687
|
}
|
|
1676
1688
|
}
|
|
1677
|
-
throw new Error(`Unable to execute PowerShell. Ensure that it is installed in your system
|
|
1689
|
+
throw new Error(`Unable to execute PowerShell. Ensure that it is installed in your system`);
|
|
1678
1690
|
}
|
|
1679
1691
|
/**
|
|
1680
1692
|
* Authenticates with Azure Active Directory and returns an access token if successful.
|
|
@@ -1685,7 +1697,7 @@ class AzurePowerShellCredential {
|
|
|
1685
1697
|
*/
|
|
1686
1698
|
async getToken(scopes, options = {}) {
|
|
1687
1699
|
return trace(`${this.constructor.name}.getToken`, options, async () => {
|
|
1688
|
-
const tenantId = processMultiTenantRequest(this.tenantId,
|
|
1700
|
+
const tenantId = processMultiTenantRequest(this.tenantId, options);
|
|
1689
1701
|
if (tenantId) {
|
|
1690
1702
|
checkTenantId(logger$4, tenantId);
|
|
1691
1703
|
}
|
|
@@ -1712,7 +1724,7 @@ class AzurePowerShellCredential {
|
|
|
1712
1724
|
logger$4.getToken.info(formatError(scope, error));
|
|
1713
1725
|
throw error;
|
|
1714
1726
|
}
|
|
1715
|
-
const error = new CredentialUnavailableError(err);
|
|
1727
|
+
const error = new CredentialUnavailableError(`${err}. ${powerShellPublicErrorMessages.troubleshoot}`);
|
|
1716
1728
|
logger$4.getToken.info(formatError(scope, error));
|
|
1717
1729
|
throw error;
|
|
1718
1730
|
}
|
|
@@ -1772,7 +1784,7 @@ class ClientSecretCredential {
|
|
|
1772
1784
|
*/
|
|
1773
1785
|
constructor(tenantId, clientId, clientSecret, options = {}) {
|
|
1774
1786
|
if (!tenantId || !clientId || !clientSecret) {
|
|
1775
|
-
throw new Error("ClientSecretCredential: tenantId, clientId, and clientSecret are required parameters.");
|
|
1787
|
+
throw new Error("ClientSecretCredential: tenantId, clientId, and clientSecret are required parameters. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.");
|
|
1776
1788
|
}
|
|
1777
1789
|
this.msalFlow = new MsalClientSecret(Object.assign(Object.assign({}, options), { logger: logger$5,
|
|
1778
1790
|
clientId,
|
|
@@ -1800,14 +1812,15 @@ const readFileAsync = util.promisify(fs.readFile);
|
|
|
1800
1812
|
/**
|
|
1801
1813
|
* Tries to asynchronously load a certificate from the given path.
|
|
1802
1814
|
*
|
|
1803
|
-
* @param
|
|
1815
|
+
* @param configuration - Either the PEM value or the path to the certificate.
|
|
1804
1816
|
* @param sendCertificateChain - Option to include x5c header for SubjectName and Issuer name authorization.
|
|
1805
1817
|
* @returns - The certificate parts, or `undefined` if the certificate could not be loaded.
|
|
1806
1818
|
* @internal
|
|
1807
1819
|
*/
|
|
1808
|
-
async function parseCertificate(
|
|
1820
|
+
async function parseCertificate(configuration, sendCertificateChain) {
|
|
1809
1821
|
const certificateParts = {};
|
|
1810
|
-
certificateParts.certificateContents =
|
|
1822
|
+
certificateParts.certificateContents =
|
|
1823
|
+
configuration.certificate || (await readFileAsync(configuration.certificatePath, "utf8"));
|
|
1811
1824
|
if (sendCertificateChain) {
|
|
1812
1825
|
certificateParts.x5c = certificateParts.certificateContents;
|
|
1813
1826
|
}
|
|
@@ -1838,13 +1851,13 @@ class MsalClientCertificate extends MsalNode {
|
|
|
1838
1851
|
constructor(options) {
|
|
1839
1852
|
super(options);
|
|
1840
1853
|
this.requiresConfidential = true;
|
|
1841
|
-
this.
|
|
1854
|
+
this.configuration = options.configuration;
|
|
1842
1855
|
this.sendCertificateChain = options.sendCertificateChain;
|
|
1843
1856
|
}
|
|
1844
1857
|
// Changing the MSAL configuration asynchronously
|
|
1845
1858
|
async init(options) {
|
|
1846
1859
|
try {
|
|
1847
|
-
const parts = await parseCertificate(this.
|
|
1860
|
+
const parts = await parseCertificate(this.configuration, this.sendCertificateChain);
|
|
1848
1861
|
this.msalConfig.auth.clientCertificate = {
|
|
1849
1862
|
thumbprint: parts.thumbprint,
|
|
1850
1863
|
privateKey: parts.certificateContents,
|
|
@@ -1877,7 +1890,8 @@ class MsalClientCertificate extends MsalNode {
|
|
|
1877
1890
|
}
|
|
1878
1891
|
|
|
1879
1892
|
// Copyright (c) Microsoft Corporation.
|
|
1880
|
-
const
|
|
1893
|
+
const credentialName = "ClientCertificateCredential";
|
|
1894
|
+
const logger$6 = credentialLogger(credentialName);
|
|
1881
1895
|
/**
|
|
1882
1896
|
* Enables authentication to Azure Active Directory using a PEM-encoded
|
|
1883
1897
|
* certificate that is assigned to an App Registration. More information
|
|
@@ -1887,20 +1901,22 @@ const logger$6 = credentialLogger("ClientCertificateCredential");
|
|
|
1887
1901
|
*
|
|
1888
1902
|
*/
|
|
1889
1903
|
class ClientCertificateCredential {
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
throw new Error("ClientCertificateCredential: tenantId, clientId, and certificatePath are required parameters.");
|
|
1904
|
+
constructor(tenantId, clientId, certificatePathOrConfiguration, options = {}) {
|
|
1905
|
+
if (!tenantId || !clientId) {
|
|
1906
|
+
throw new Error(`${credentialName}: tenantId and clientId are required parameters.`);
|
|
1907
|
+
}
|
|
1908
|
+
const configuration = Object.assign({}, (typeof certificatePathOrConfiguration === "string"
|
|
1909
|
+
? {
|
|
1910
|
+
certificatePath: certificatePathOrConfiguration
|
|
1911
|
+
}
|
|
1912
|
+
: certificatePathOrConfiguration));
|
|
1913
|
+
if (!configuration || !(configuration.certificate || configuration.certificatePath)) {
|
|
1914
|
+
throw new Error(`${credentialName}: Provide either a PEM certificate in string form, or the path to that certificate in the filesystem. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`);
|
|
1902
1915
|
}
|
|
1903
|
-
|
|
1916
|
+
if (configuration.certificate && configuration.certificatePath) {
|
|
1917
|
+
throw new Error(`${credentialName}: To avoid unexpected behaviors, providing both the contents of a PEM certificate and the path to a PEM certificate is forbidden. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`);
|
|
1918
|
+
}
|
|
1919
|
+
this.msalFlow = new MsalClientCertificate(Object.assign(Object.assign({}, options), { configuration,
|
|
1904
1920
|
logger: logger$6,
|
|
1905
1921
|
clientId,
|
|
1906
1922
|
tenantId, sendCertificateChain: options.sendCertificateChain, tokenCredentialOptions: options }));
|
|
@@ -1914,7 +1930,7 @@ class ClientCertificateCredential {
|
|
|
1914
1930
|
* TokenCredential implementation might make.
|
|
1915
1931
|
*/
|
|
1916
1932
|
async getToken(scopes, options = {}) {
|
|
1917
|
-
return trace(`${
|
|
1933
|
+
return trace(`${credentialName}.getToken`, options, async (newOptions) => {
|
|
1918
1934
|
const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];
|
|
1919
1935
|
return this.msalFlow.getToken(arrayScopes, newOptions);
|
|
1920
1936
|
});
|
|
@@ -1958,8 +1974,6 @@ const logger$7 = credentialLogger("UsernamePasswordCredential");
|
|
|
1958
1974
|
* trust so you should only use it when other, more secure credential
|
|
1959
1975
|
* types can't be used.
|
|
1960
1976
|
*/
|
|
1961
|
-
// We'll be using InteractiveCredential as the base of this class, which requires us to support authenticate(),
|
|
1962
|
-
// to reduce the number of times we send the password over the network.
|
|
1963
1977
|
class UsernamePasswordCredential {
|
|
1964
1978
|
/**
|
|
1965
1979
|
* Creates an instance of the UsernamePasswordCredential with the details
|
|
@@ -1974,7 +1988,7 @@ class UsernamePasswordCredential {
|
|
|
1974
1988
|
*/
|
|
1975
1989
|
constructor(tenantId, clientId, username, password, options = {}) {
|
|
1976
1990
|
if (!tenantId || !clientId || !username || !password) {
|
|
1977
|
-
throw new Error("UsernamePasswordCredential: tenantId, clientId, username and password are required parameters.");
|
|
1991
|
+
throw new Error("UsernamePasswordCredential: tenantId, clientId, username and password are required parameters. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.");
|
|
1978
1992
|
}
|
|
1979
1993
|
this.msalFlow = new MsalUsernamePassword(Object.assign(Object.assign({}, options), { logger: logger$7,
|
|
1980
1994
|
clientId,
|
|
@@ -2021,23 +2035,7 @@ const AllSupportedEnvironmentVariables = [
|
|
|
2021
2035
|
const logger$8 = credentialLogger("EnvironmentCredential");
|
|
2022
2036
|
/**
|
|
2023
2037
|
* Enables authentication to Azure Active Directory using client secret
|
|
2024
|
-
* details configured in
|
|
2025
|
-
*
|
|
2026
|
-
* Required environment variables:
|
|
2027
|
-
* - `AZURE_TENANT_ID`: The Azure Active Directory tenant (directory) ID.
|
|
2028
|
-
* - `AZURE_CLIENT_ID`: The client (application) ID of an App Registration in the tenant.
|
|
2029
|
-
*
|
|
2030
|
-
* Environment variables used for client credential authentication:
|
|
2031
|
-
* - `AZURE_CLIENT_SECRET`: A client secret that was generated for the App Registration.
|
|
2032
|
-
* - `AZURE_CLIENT_CERTIFICATE_PATH`: The path to a PEM certificate to use during the authentication, instead of the client secret.
|
|
2033
|
-
*
|
|
2034
|
-
* Alternatively, users can provide environment variables for username and password authentication:
|
|
2035
|
-
* - `AZURE_USERNAME`: Username to authenticate with.
|
|
2036
|
-
* - `AZURE_PASSWORD`: Password to authenticate with.
|
|
2037
|
-
*
|
|
2038
|
-
* This credential ultimately uses a {@link ClientSecretCredential} to
|
|
2039
|
-
* perform the authentication using these details. Please consult the
|
|
2040
|
-
* documentation of that class for more details.
|
|
2038
|
+
* details configured in environment variables
|
|
2041
2039
|
*/
|
|
2042
2040
|
class EnvironmentCredential {
|
|
2043
2041
|
/**
|
|
@@ -2077,7 +2075,7 @@ class EnvironmentCredential {
|
|
|
2077
2075
|
const certificatePath = process.env.AZURE_CLIENT_CERTIFICATE_PATH;
|
|
2078
2076
|
if (tenantId && clientId && certificatePath) {
|
|
2079
2077
|
logger$8.info(`Invoking ClientCertificateCredential with tenant ID: ${tenantId}, clientId: ${clientId} and certificatePath: ${certificatePath}`);
|
|
2080
|
-
this._credential = new ClientCertificateCredential(tenantId, clientId, certificatePath, options);
|
|
2078
|
+
this._credential = new ClientCertificateCredential(tenantId, clientId, { certificatePath }, options);
|
|
2081
2079
|
return;
|
|
2082
2080
|
}
|
|
2083
2081
|
const username = process.env.AZURE_USERNAME;
|
|
@@ -2103,7 +2101,7 @@ class EnvironmentCredential {
|
|
|
2103
2101
|
}
|
|
2104
2102
|
catch (err) {
|
|
2105
2103
|
const authenticationError = new AuthenticationError(400, {
|
|
2106
|
-
error: "EnvironmentCredential authentication failed.",
|
|
2104
|
+
error: "EnvironmentCredential authentication failed. To troubleshoot, visit https://aka.ms/azsdk/js/identity/environmentcredential/troubleshoot.",
|
|
2107
2105
|
error_description: err.message
|
|
2108
2106
|
.toString()
|
|
2109
2107
|
.split("More details:")
|
|
@@ -2113,7 +2111,7 @@ class EnvironmentCredential {
|
|
|
2113
2111
|
throw authenticationError;
|
|
2114
2112
|
}
|
|
2115
2113
|
}
|
|
2116
|
-
throw new CredentialUnavailableError("EnvironmentCredential is unavailable. No underlying credential could be used.");
|
|
2114
|
+
throw new CredentialUnavailableError("EnvironmentCredential is unavailable. No underlying credential could be used. To troubleshoot, visit https://aka.ms/azsdk/js/identity/environmentcredential/troubleshoot.");
|
|
2117
2115
|
});
|
|
2118
2116
|
}
|
|
2119
2117
|
}
|
|
@@ -2274,7 +2272,7 @@ function expiresInParser$2(requestBody) {
|
|
|
2274
2272
|
if (requestBody.expires_on) {
|
|
2275
2273
|
// Use the expires_on timestamp if it's available
|
|
2276
2274
|
const expires = +requestBody.expires_on * 1000;
|
|
2277
|
-
logger$b.info(`${msiName$2}:
|
|
2275
|
+
logger$b.info(`${msiName$2}: Using expires_on: ${expires} (original value: ${requestBody.expires_on})`);
|
|
2278
2276
|
return expires;
|
|
2279
2277
|
}
|
|
2280
2278
|
else {
|
|
@@ -2284,29 +2282,41 @@ function expiresInParser$2(requestBody) {
|
|
|
2284
2282
|
return expires;
|
|
2285
2283
|
}
|
|
2286
2284
|
}
|
|
2287
|
-
function prepareRequestOptions$2(scopes, clientId) {
|
|
2285
|
+
function prepareRequestOptions$2(scopes, clientId, options) {
|
|
2288
2286
|
var _a;
|
|
2289
2287
|
const resource = mapScopesToResource(scopes);
|
|
2290
2288
|
if (!resource) {
|
|
2291
2289
|
throw new Error(`${msiName$2}: Multiple scopes are not supported.`);
|
|
2292
2290
|
}
|
|
2293
|
-
const
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
if (
|
|
2298
|
-
queryParameters
|
|
2291
|
+
const { skipQuery, skipMetadataHeader } = options || {};
|
|
2292
|
+
let query = "";
|
|
2293
|
+
// Pod Identity will try to process this request even if the Metadata header is missing.
|
|
2294
|
+
// We can exclude the request query to ensure no IMDS endpoint tries to process the ping request.
|
|
2295
|
+
if (!skipQuery) {
|
|
2296
|
+
const queryParameters = {
|
|
2297
|
+
resource,
|
|
2298
|
+
"api-version": imdsApiVersion
|
|
2299
|
+
};
|
|
2300
|
+
if (clientId) {
|
|
2301
|
+
queryParameters.client_id = clientId;
|
|
2302
|
+
}
|
|
2303
|
+
const params = new URLSearchParams(queryParameters);
|
|
2304
|
+
query = `?${params.toString()}`;
|
|
2299
2305
|
}
|
|
2300
|
-
const params = new URLSearchParams(queryParameters);
|
|
2301
|
-
const query = params.toString();
|
|
2302
2306
|
const url = new URL(imdsEndpointPath, (_a = process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST) !== null && _a !== void 0 ? _a : imdsHost);
|
|
2307
|
+
const rawHeaders = {
|
|
2308
|
+
Accept: "application/json",
|
|
2309
|
+
Metadata: "true"
|
|
2310
|
+
};
|
|
2311
|
+
// Remove the Metadata header to invoke a request error from some IMDS endpoints.
|
|
2312
|
+
if (skipMetadataHeader) {
|
|
2313
|
+
delete rawHeaders.Metadata;
|
|
2314
|
+
}
|
|
2303
2315
|
return {
|
|
2304
|
-
|
|
2316
|
+
// In this case, the `?` should be added in the "query" variable `skipQuery` is not set.
|
|
2317
|
+
url: `${url}${query}`,
|
|
2305
2318
|
method: "GET",
|
|
2306
|
-
headers: coreRestPipeline.createHttpHeaders(
|
|
2307
|
-
Accept: "application/json",
|
|
2308
|
-
Metadata: "true"
|
|
2309
|
-
})
|
|
2319
|
+
headers: coreRestPipeline.createHttpHeaders(rawHeaders)
|
|
2310
2320
|
};
|
|
2311
2321
|
}
|
|
2312
2322
|
// 800ms -> 1600ms -> 3200ms
|
|
@@ -2328,13 +2338,10 @@ const imdsMsi = {
|
|
|
2328
2338
|
if (process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST) {
|
|
2329
2339
|
return true;
|
|
2330
2340
|
}
|
|
2331
|
-
const requestOptions = prepareRequestOptions$2(resource, clientId
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
// IMDS endpoint
|
|
2336
|
-
requestOptions.headers.delete("Metadata");
|
|
2337
|
-
}
|
|
2341
|
+
const requestOptions = prepareRequestOptions$2(resource, clientId, {
|
|
2342
|
+
skipMetadataHeader: true,
|
|
2343
|
+
skipQuery: true
|
|
2344
|
+
});
|
|
2338
2345
|
requestOptions.tracingOptions = options.tracingOptions;
|
|
2339
2346
|
try {
|
|
2340
2347
|
// Create a request with a timeout since we expect that
|
|
@@ -2641,7 +2648,7 @@ class ManagedIdentityCredential {
|
|
|
2641
2648
|
*/
|
|
2642
2649
|
async getToken(scopes, options) {
|
|
2643
2650
|
let result = null;
|
|
2644
|
-
const { span, updatedOptions } = createSpan("ManagedIdentityCredential
|
|
2651
|
+
const { span, updatedOptions } = createSpan("ManagedIdentityCredential.getToken", options);
|
|
2645
2652
|
try {
|
|
2646
2653
|
// isEndpointAvailable can be true, false, or null,
|
|
2647
2654
|
// If it's null, it means we don't yet know whether
|
|
@@ -2754,22 +2761,26 @@ const defaultCredentials = [
|
|
|
2754
2761
|
];
|
|
2755
2762
|
/**
|
|
2756
2763
|
* Provides a default {@link ChainedTokenCredential} configuration that should
|
|
2757
|
-
* work for most applications that use the Azure SDK.
|
|
2758
|
-
* types will be tried, in order:
|
|
2759
|
-
*
|
|
2760
|
-
* - {@link EnvironmentCredential}
|
|
2761
|
-
* - {@link ManagedIdentityCredential}
|
|
2762
|
-
* - {@link VisualStudioCodeCredential}
|
|
2763
|
-
* - {@link AzureCliCredential}
|
|
2764
|
-
* - {@link AzurePowerShellCredential}
|
|
2765
|
-
*
|
|
2766
|
-
* Consult the documentation of these credential types for more information
|
|
2767
|
-
* on how they attempt authentication.
|
|
2764
|
+
* work for most applications that use the Azure SDK.
|
|
2768
2765
|
*/
|
|
2769
2766
|
class DefaultAzureCredential extends ChainedTokenCredential {
|
|
2770
2767
|
/**
|
|
2771
2768
|
* Creates an instance of the DefaultAzureCredential class.
|
|
2772
2769
|
*
|
|
2770
|
+
* This credential provides a default {@link ChainedTokenCredential} configuration that should
|
|
2771
|
+
* work for most applications that use the Azure SDK.
|
|
2772
|
+
*
|
|
2773
|
+
* The following credential types will be tried, in order:
|
|
2774
|
+
*
|
|
2775
|
+
* - {@link EnvironmentCredential}
|
|
2776
|
+
* - {@link ManagedIdentityCredential}
|
|
2777
|
+
* - {@link VisualStudioCodeCredential}
|
|
2778
|
+
* - {@link AzureCliCredential}
|
|
2779
|
+
* - {@link AzurePowerShellCredential}
|
|
2780
|
+
*
|
|
2781
|
+
* Consult the documentation of these credential types for more information
|
|
2782
|
+
* on how they attempt authentication.
|
|
2783
|
+
*
|
|
2773
2784
|
* **Note**: `VisualStudioCodeCredential` is provided by a plugin package:
|
|
2774
2785
|
* `@azure/identity-vscode`. If this package is not installed and registered
|
|
2775
2786
|
* using the plugin API (`useIdentityPlugin`), then authentication using
|
|
@@ -2780,7 +2791,7 @@ class DefaultAzureCredential extends ChainedTokenCredential {
|
|
|
2780
2791
|
constructor(options) {
|
|
2781
2792
|
super(...defaultCredentials.map((ctor) => new ctor(options)));
|
|
2782
2793
|
this.UnavailableMessage =
|
|
2783
|
-
"DefaultAzureCredential => failed to retrieve a token from the included credentials";
|
|
2794
|
+
"DefaultAzureCredential => failed to retrieve a token from the included credentials. To troubleshoot, visit https://aka.ms/azsdk/js/identity/defaultazurecredential/troubleshoot.";
|
|
2784
2795
|
}
|
|
2785
2796
|
}
|
|
2786
2797
|
|
|
@@ -2932,18 +2943,18 @@ const logger$f = credentialLogger("InteractiveBrowserCredential");
|
|
|
2932
2943
|
/**
|
|
2933
2944
|
* Enables authentication to Azure Active Directory inside of the web browser
|
|
2934
2945
|
* using the interactive login flow.
|
|
2935
|
-
*
|
|
2936
|
-
* This credential uses the [Authorization Code Flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-auth-code-flow).
|
|
2937
|
-
* On Node.js, it will open a browser window while it listens for a redirect response from the authentication service.
|
|
2938
|
-
* On browsers, it authenticates via popups. The `loginStyle` optional parameter can be set to `redirect` to authenticate by redirecting the user to an Azure secure login page, which then will redirect the user back to the web application where the authentication started.
|
|
2939
|
-
*
|
|
2940
|
-
* For Node.js, if a `clientId` is provided, the Azure Active Directory application will need to be configured to have a "Mobile and desktop applications" redirect endpoint.
|
|
2941
|
-
* Follow our guide on [setting up Redirect URIs for Desktop apps that calls to web APIs](https://docs.microsoft.com/azure/active-directory/develop/scenario-desktop-app-registration#redirect-uris).
|
|
2942
2946
|
*/
|
|
2943
2947
|
class InteractiveBrowserCredential {
|
|
2944
2948
|
/**
|
|
2945
2949
|
* Creates an instance of InteractiveBrowserCredential with the details needed.
|
|
2946
2950
|
*
|
|
2951
|
+
* This credential uses the [Authorization Code Flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-auth-code-flow).
|
|
2952
|
+
* On Node.js, it will open a browser window while it listens for a redirect response from the authentication service.
|
|
2953
|
+
* On browsers, it authenticates via popups. The `loginStyle` optional parameter can be set to `redirect` to authenticate by redirecting the user to an Azure secure login page, which then will redirect the user back to the web application where the authentication started.
|
|
2954
|
+
*
|
|
2955
|
+
* For Node.js, if a `clientId` is provided, the Azure Active Directory application will need to be configured to have a "Mobile and desktop applications" redirect endpoint.
|
|
2956
|
+
* Follow our guide on [setting up Redirect URIs for Desktop apps that calls to web APIs](https://docs.microsoft.com/azure/active-directory/develop/scenario-desktop-app-registration#redirect-uris).
|
|
2957
|
+
*
|
|
2947
2958
|
* @param options - Options for configuring the client which makes the authentication requests.
|
|
2948
2959
|
*/
|
|
2949
2960
|
constructor(options = {}) {
|
|
@@ -3045,6 +3056,20 @@ class DeviceCodeCredential {
|
|
|
3045
3056
|
* Creates an instance of DeviceCodeCredential with the details needed
|
|
3046
3057
|
* to initiate the device code authorization flow with Azure Active Directory.
|
|
3047
3058
|
*
|
|
3059
|
+
* A message will be logged, giving users a code that they can use to authenticate once they go to https://microsoft.com/devicelogin
|
|
3060
|
+
*
|
|
3061
|
+
* Developers can configure how this message is shown by passing a custom `userPromptCallback`:
|
|
3062
|
+
*
|
|
3063
|
+
* ```js
|
|
3064
|
+
* const credential = new DeviceCodeCredential({
|
|
3065
|
+
* tenantId: env.AZURE_TENANT_ID,
|
|
3066
|
+
* clientId: env.AZURE_CLIENT_ID,
|
|
3067
|
+
* userPromptCallback: (info) => {
|
|
3068
|
+
* console.log("CUSTOMIZED PROMPT CALLBACK", info.message);
|
|
3069
|
+
* }
|
|
3070
|
+
* });
|
|
3071
|
+
* ```
|
|
3072
|
+
*
|
|
3048
3073
|
* @param options - Options for configuring the client which makes the authentication requests.
|
|
3049
3074
|
*/
|
|
3050
3075
|
constructor(options) {
|
|
@@ -3097,7 +3122,7 @@ class DeviceCodeCredential {
|
|
|
3097
3122
|
class MsalAuthorizationCode extends MsalNode {
|
|
3098
3123
|
constructor(options) {
|
|
3099
3124
|
super(options);
|
|
3100
|
-
this.logger = credentialLogger("
|
|
3125
|
+
this.logger = credentialLogger("Node.js MSAL Authorization Code");
|
|
3101
3126
|
this.redirectUri = options.redirectUri;
|
|
3102
3127
|
this.authorizationCode = options.authorizationCode;
|
|
3103
3128
|
if (options.clientSecret) {
|
|
@@ -3175,36 +3200,6 @@ class AuthorizationCodeCredential {
|
|
|
3175
3200
|
}
|
|
3176
3201
|
}
|
|
3177
3202
|
|
|
3178
|
-
// Copyright (c) Microsoft Corporation.
|
|
3179
|
-
const ApplicationCredentials = [
|
|
3180
|
-
EnvironmentCredential,
|
|
3181
|
-
DefaultManagedIdentityCredential
|
|
3182
|
-
];
|
|
3183
|
-
/**
|
|
3184
|
-
* Provides a default {@link ChainedTokenCredential} configuration that should
|
|
3185
|
-
* work for most applications that use the Azure SDK. The following credential
|
|
3186
|
-
* types will be tried, in order:
|
|
3187
|
-
*
|
|
3188
|
-
* - {@link EnvironmentCredential}
|
|
3189
|
-
* - {@link ManagedIdentityCredential}
|
|
3190
|
-
|
|
3191
|
-
*
|
|
3192
|
-
* Consult the documentation of these credential types for more information
|
|
3193
|
-
* on how they attempt authentication.
|
|
3194
|
-
*/
|
|
3195
|
-
class ApplicationCredential extends ChainedTokenCredential {
|
|
3196
|
-
/**
|
|
3197
|
-
* Creates an instance of the ApplicationCredential class.
|
|
3198
|
-
*
|
|
3199
|
-
* @param options - Optional parameters. See {@link ApplicationCredentialOptions}.
|
|
3200
|
-
*/
|
|
3201
|
-
constructor(options) {
|
|
3202
|
-
super(...ApplicationCredentials.map((ctor) => new ctor(options)));
|
|
3203
|
-
this.UnavailableMessage =
|
|
3204
|
-
"ApplicationCredential => failed to retrieve a token from the included credentials";
|
|
3205
|
-
}
|
|
3206
|
-
}
|
|
3207
|
-
|
|
3208
3203
|
// Copyright (c) Microsoft Corporation.
|
|
3209
3204
|
/**
|
|
3210
3205
|
* MSAL on behalf of flow. Calls to MSAL's confidential application's `acquireTokenOnBehalfOf` during `doGetToken`.
|
|
@@ -3224,7 +3219,7 @@ class MsalOnBehalfOf extends MsalNode {
|
|
|
3224
3219
|
async init(options) {
|
|
3225
3220
|
if (this.certificatePath) {
|
|
3226
3221
|
try {
|
|
3227
|
-
const parts = await parseCertificate(this.certificatePath, this.sendCertificateChain);
|
|
3222
|
+
const parts = await parseCertificate({ certificatePath: this.certificatePath }, this.sendCertificateChain);
|
|
3228
3223
|
this.msalConfig.auth.clientCertificate = {
|
|
3229
3224
|
thumbprint: parts.thumbprint,
|
|
3230
3225
|
privateKey: parts.certificateContents,
|
|
@@ -3258,8 +3253,8 @@ class MsalOnBehalfOf extends MsalNode {
|
|
|
3258
3253
|
}
|
|
3259
3254
|
|
|
3260
3255
|
// Copyright (c) Microsoft Corporation.
|
|
3261
|
-
const credentialName = "OnBehalfOfCredential";
|
|
3262
|
-
const logger$i = credentialLogger(credentialName);
|
|
3256
|
+
const credentialName$1 = "OnBehalfOfCredential";
|
|
3257
|
+
const logger$i = credentialLogger(credentialName$1);
|
|
3263
3258
|
/**
|
|
3264
3259
|
* Enables authentication to Azure Active Directory using the [On Behalf Of flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-on-behalf-of-flow).
|
|
3265
3260
|
*/
|
|
@@ -3283,22 +3278,17 @@ class OnBehalfOfCredential {
|
|
|
3283
3278
|
* await client.getKey("key-name");
|
|
3284
3279
|
* ```
|
|
3285
3280
|
*
|
|
3286
|
-
* @param configuration - Configuration specific to this credential.
|
|
3287
3281
|
* @param options - Optional parameters, generally common across credentials.
|
|
3288
3282
|
*/
|
|
3289
|
-
constructor(
|
|
3290
|
-
this.configuration = configuration;
|
|
3283
|
+
constructor(options) {
|
|
3291
3284
|
this.options = options;
|
|
3292
|
-
const {
|
|
3293
|
-
const
|
|
3294
|
-
const
|
|
3295
|
-
if (!tenantId ||
|
|
3296
|
-
|
|
3297
|
-
!(secretConfiguration.clientSecret || certificateConfiguration.certificatePath) ||
|
|
3298
|
-
!userAssertionToken) {
|
|
3299
|
-
throw new Error(`${credentialName}: tenantId, clientId, clientSecret (or certificatePath) and userAssertionToken are required parameters.`);
|
|
3285
|
+
const { clientSecret } = options;
|
|
3286
|
+
const { certificatePath } = options;
|
|
3287
|
+
const { tenantId, clientId, userAssertionToken } = options;
|
|
3288
|
+
if (!tenantId || !clientId || !(clientSecret || certificatePath) || !userAssertionToken) {
|
|
3289
|
+
throw new Error(`${credentialName$1}: tenantId, clientId, clientSecret (or certificatePath) and userAssertionToken are required parameters.`);
|
|
3300
3290
|
}
|
|
3301
|
-
this.msalFlow = new MsalOnBehalfOf(Object.assign(Object.assign(
|
|
3291
|
+
this.msalFlow = new MsalOnBehalfOf(Object.assign(Object.assign({}, this.options), { logger: logger$i, tokenCredentialOptions: this.options }));
|
|
3302
3292
|
}
|
|
3303
3293
|
/**
|
|
3304
3294
|
* Authenticates with Azure Active Directory and returns an access token if successful.
|
|
@@ -3308,7 +3298,7 @@ class OnBehalfOfCredential {
|
|
|
3308
3298
|
* @param options - The options used to configure the underlying network requests.
|
|
3309
3299
|
*/
|
|
3310
3300
|
async getToken(scopes, options = {}) {
|
|
3311
|
-
return trace(`${credentialName}.getToken`, options, async (newOptions) => {
|
|
3301
|
+
return trace(`${credentialName$1}.getToken`, options, async (newOptions) => {
|
|
3312
3302
|
const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];
|
|
3313
3303
|
return this.msalFlow.getToken(arrayScopes, newOptions);
|
|
3314
3304
|
});
|
|
@@ -3325,7 +3315,6 @@ function getDefaultAzureCredential() {
|
|
|
3325
3315
|
|
|
3326
3316
|
exports.AggregateAuthenticationError = AggregateAuthenticationError;
|
|
3327
3317
|
exports.AggregateAuthenticationErrorName = AggregateAuthenticationErrorName;
|
|
3328
|
-
exports.ApplicationCredential = ApplicationCredential;
|
|
3329
3318
|
exports.AuthenticationError = AuthenticationError;
|
|
3330
3319
|
exports.AuthenticationErrorName = AuthenticationErrorName;
|
|
3331
3320
|
exports.AuthenticationRequiredError = AuthenticationRequiredError;
|