@azure/identity 2.0.0-beta.6 → 2.0.2-alpha.20211028.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/CHANGELOG.md +160 -12
- package/README.md +51 -3
- package/dist/index.js +307 -238
- 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 +10 -10
- 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/fabricMsi.js +7 -2
- package/dist-esm/src/credentials/managedIdentityCredential/fabricMsi.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 +4 -5
- package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/utils.js +4 -1
- package/dist-esm/src/credentials/managedIdentityCredential/utils.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 +10 -8
- 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
|
@@ -10,7 +10,7 @@ var coreTracing = require('@azure/core-tracing');
|
|
|
10
10
|
var coreUtil = require('@azure/core-util');
|
|
11
11
|
var coreRestPipeline = require('@azure/core-rest-pipeline');
|
|
12
12
|
var abortController = require('@azure/abort-controller');
|
|
13
|
-
var logger$
|
|
13
|
+
var logger$k = require('@azure/logger');
|
|
14
14
|
var msalCommon = require('@azure/msal-common');
|
|
15
15
|
var uuid = require('uuid');
|
|
16
16
|
var fs = require('fs');
|
|
@@ -18,8 +18,10 @@ 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');
|
|
24
|
+
var https = _interopDefault(require('https'));
|
|
23
25
|
var http = _interopDefault(require('http'));
|
|
24
26
|
var open = _interopDefault(require('open'));
|
|
25
27
|
var stoppable = _interopDefault(require('stoppable'));
|
|
@@ -165,6 +167,21 @@ function convertOAuthErrorResponseToErrorResponse(errorBody) {
|
|
|
165
167
|
traceId: errorBody.trace_id
|
|
166
168
|
};
|
|
167
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Error used to enforce authentication after trying to retrieve a token silently.
|
|
172
|
+
*/
|
|
173
|
+
class AuthenticationRequiredError extends Error {
|
|
174
|
+
constructor(
|
|
175
|
+
/**
|
|
176
|
+
* 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.
|
|
177
|
+
*/
|
|
178
|
+
options) {
|
|
179
|
+
super(options.message);
|
|
180
|
+
this.scopes = options.scopes;
|
|
181
|
+
this.getTokenOptions = options.getTokenOptions;
|
|
182
|
+
this.name = "AuthenticationRequiredError";
|
|
183
|
+
}
|
|
184
|
+
}
|
|
168
185
|
|
|
169
186
|
// Copyright (c) Microsoft Corporation.
|
|
170
187
|
// Licensed under the MIT license.
|
|
@@ -183,7 +200,7 @@ function getIdentityTokenEndpointSuffix(tenantId) {
|
|
|
183
200
|
* @internal
|
|
184
201
|
*/
|
|
185
202
|
const createSpan = coreTracing.createSpanFunction({
|
|
186
|
-
packagePrefix: "
|
|
203
|
+
packagePrefix: "",
|
|
187
204
|
namespace: "Microsoft.AAD"
|
|
188
205
|
});
|
|
189
206
|
/**
|
|
@@ -224,7 +241,7 @@ async function trace(operationName, options, fn, createSpanFn = createSpan) {
|
|
|
224
241
|
/**
|
|
225
242
|
* The AzureLogger used for all clients within the identity package
|
|
226
243
|
*/
|
|
227
|
-
const logger = logger$
|
|
244
|
+
const logger = logger$k.createClientLogger("identity");
|
|
228
245
|
/**
|
|
229
246
|
* Separates a list of environment variable names into a plain object with two arrays: an array of missing environment variables and another array with assigned environment variables.
|
|
230
247
|
* @param supportedEnvVars - List of environment variable names
|
|
@@ -315,7 +332,7 @@ function getIdentityClientAuthorityHost(options) {
|
|
|
315
332
|
class IdentityClient extends coreClient.ServiceClient {
|
|
316
333
|
constructor(options) {
|
|
317
334
|
var _a;
|
|
318
|
-
const packageDetails = `azsdk-js-identity/2.0.
|
|
335
|
+
const packageDetails = `azsdk-js-identity/2.0.2`;
|
|
319
336
|
const userAgentPrefix = ((_a = options === null || options === void 0 ? void 0 : options.userAgentOptions) === null || _a === void 0 ? void 0 : _a.userAgentPrefix)
|
|
320
337
|
? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
|
|
321
338
|
: `${packageDetails}`;
|
|
@@ -511,28 +528,6 @@ function resolveTenantId(logger, tenantId, clientId) {
|
|
|
511
528
|
return "organizations";
|
|
512
529
|
}
|
|
513
530
|
|
|
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
531
|
// Copyright (c) Microsoft Corporation.
|
|
537
532
|
/**
|
|
538
533
|
* Latest AuthenticationRecord version
|
|
@@ -546,7 +541,11 @@ const LatestAuthenticationRecordVersion = "1.0";
|
|
|
546
541
|
function ensureValidMsalToken(scopes, logger, msalToken, getTokenOptions) {
|
|
547
542
|
const error = (message) => {
|
|
548
543
|
logger.getToken.info(message);
|
|
549
|
-
return new AuthenticationRequiredError(
|
|
544
|
+
return new AuthenticationRequiredError({
|
|
545
|
+
scopes: Array.isArray(scopes) ? scopes : [scopes],
|
|
546
|
+
getTokenOptions,
|
|
547
|
+
message
|
|
548
|
+
});
|
|
550
549
|
};
|
|
551
550
|
if (!msalToken) {
|
|
552
551
|
throw error("No response");
|
|
@@ -674,7 +673,7 @@ class MsalBaseUtilities {
|
|
|
674
673
|
error.name === "AbortError") {
|
|
675
674
|
return error;
|
|
676
675
|
}
|
|
677
|
-
return new AuthenticationRequiredError(scopes, getTokenOptions, error.message);
|
|
676
|
+
return new AuthenticationRequiredError({ scopes, getTokenOptions, message: error.message });
|
|
678
677
|
}
|
|
679
678
|
}
|
|
680
679
|
// transformations.ts
|
|
@@ -738,6 +737,40 @@ function deserializeAuthenticationRecord(serializedRecord) {
|
|
|
738
737
|
}
|
|
739
738
|
|
|
740
739
|
// Copyright (c) Microsoft Corporation.
|
|
740
|
+
// Licensed under the MIT license.
|
|
741
|
+
/**
|
|
742
|
+
* @internal
|
|
743
|
+
*/
|
|
744
|
+
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.";
|
|
745
|
+
/**
|
|
746
|
+
* @internal
|
|
747
|
+
*/
|
|
748
|
+
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`.";
|
|
749
|
+
/**
|
|
750
|
+
* Of getToken contains a tenantId, this functions allows picking this tenantId as the appropriate for authentication,
|
|
751
|
+
* unless multitenant authentication has been disabled through the AZURE_IDENTITY_DISABLE_MULTITENANTAUTH (on Node.js),
|
|
752
|
+
* or unless the original tenant Id is `adfs`.
|
|
753
|
+
* @internal
|
|
754
|
+
*/
|
|
755
|
+
function processMultiTenantRequest(tenantId, getTokenOptions) {
|
|
756
|
+
if (!(getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.tenantId)) {
|
|
757
|
+
return tenantId;
|
|
758
|
+
}
|
|
759
|
+
if (process.env.AZURE_IDENTITY_DISABLE_MULTITENANTAUTH) {
|
|
760
|
+
throw new Error(multiTenantDisabledErrorMessage);
|
|
761
|
+
}
|
|
762
|
+
if (tenantId === "adfs") {
|
|
763
|
+
throw new Error(multiTenantADFSErrorMessage);
|
|
764
|
+
}
|
|
765
|
+
return getTokenOptions === null || getTokenOptions === void 0 ? void 0 : getTokenOptions.tenantId;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// Copyright (c) Microsoft Corporation.
|
|
769
|
+
// Licensed under the MIT license.
|
|
770
|
+
/**
|
|
771
|
+
* Helps specify a regional authority, or "AutoDiscoverRegion" to auto-detect the region.
|
|
772
|
+
*/
|
|
773
|
+
var RegionalAuthority;
|
|
741
774
|
(function (RegionalAuthority) {
|
|
742
775
|
/** Instructs MSAL to attempt to discover the region */
|
|
743
776
|
RegionalAuthority["AutoDiscoverRegion"] = "AutoDiscoverRegion";
|
|
@@ -845,31 +878,7 @@ function deserializeAuthenticationRecord(serializedRecord) {
|
|
|
845
878
|
RegionalAuthority["GovernmentUSDodEast"] = "usdodeast";
|
|
846
879
|
/** Uses the {@link RegionalAuthority} for the Azure 'usdodcentral' region. */
|
|
847
880
|
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
|
-
}
|
|
881
|
+
})(RegionalAuthority || (RegionalAuthority = {}));
|
|
873
882
|
|
|
874
883
|
// Copyright (c) Microsoft Corporation.
|
|
875
884
|
/**
|
|
@@ -902,7 +911,6 @@ class MsalNode extends MsalBaseUtilities {
|
|
|
902
911
|
this.requiresConfidential = false;
|
|
903
912
|
this.msalConfig = this.defaultNodeMsalConfig(options);
|
|
904
913
|
this.tenantId = resolveTenantId(options.logger, options.tenantId, options.clientId);
|
|
905
|
-
this.allowMultiTenantAuthentication = options === null || options === void 0 ? void 0 : options.allowMultiTenantAuthentication;
|
|
906
914
|
this.clientId = this.msalConfig.auth.clientId;
|
|
907
915
|
// If persistence has been configured
|
|
908
916
|
if (persistenceProvider !== undefined && ((_a = options.tokenCachePersistenceOptions) === null || _a === void 0 ? void 0 : _a.enabled)) {
|
|
@@ -917,7 +925,7 @@ class MsalNode extends MsalBaseUtilities {
|
|
|
917
925
|
].join(" "));
|
|
918
926
|
}
|
|
919
927
|
this.azureRegion = (_c = options.regionalAuthority) !== null && _c !== void 0 ? _c : process.env.AZURE_REGIONAL_AUTHORITY_NAME;
|
|
920
|
-
if (this.azureRegion ===
|
|
928
|
+
if (this.azureRegion === RegionalAuthority.AutoDiscoverRegion) {
|
|
921
929
|
this.azureRegion = "AUTO_DISCOVER";
|
|
922
930
|
}
|
|
923
931
|
}
|
|
@@ -1033,7 +1041,11 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
|
1033
1041
|
var _a, _b;
|
|
1034
1042
|
await this.getActiveAccount();
|
|
1035
1043
|
if (!this.account) {
|
|
1036
|
-
throw new AuthenticationRequiredError(
|
|
1044
|
+
throw new AuthenticationRequiredError({
|
|
1045
|
+
scopes,
|
|
1046
|
+
getTokenOptions: options,
|
|
1047
|
+
message: "Silent authentication failed. We couldn't retrieve an active account from the cache."
|
|
1048
|
+
});
|
|
1037
1049
|
}
|
|
1038
1050
|
const silentRequest = {
|
|
1039
1051
|
// To be able to re-use the account, the Token Cache must also have been provided.
|
|
@@ -1056,8 +1068,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
|
1056
1068
|
* If disableAutomaticAuthentication is sent through the constructor, it will prevent MSAL from requesting the user input.
|
|
1057
1069
|
*/
|
|
1058
1070
|
async getToken(scopes, options = {}) {
|
|
1059
|
-
const tenantId = processMultiTenantRequest(this.tenantId,
|
|
1060
|
-
this.tenantId;
|
|
1071
|
+
const tenantId = processMultiTenantRequest(this.tenantId, options) || this.tenantId;
|
|
1061
1072
|
options.authority = getAuthority(tenantId, this.authorityHost);
|
|
1062
1073
|
options.correlationId = (options === null || options === void 0 ? void 0 : options.correlationId) || this.generateUuid();
|
|
1063
1074
|
await this.init(options);
|
|
@@ -1069,7 +1080,11 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
|
1069
1080
|
throw err;
|
|
1070
1081
|
}
|
|
1071
1082
|
if (options === null || options === void 0 ? void 0 : options.disableAutomaticAuthentication) {
|
|
1072
|
-
throw new AuthenticationRequiredError(
|
|
1083
|
+
throw new AuthenticationRequiredError({
|
|
1084
|
+
scopes,
|
|
1085
|
+
getTokenOptions: options,
|
|
1086
|
+
message: "Automatic authentication has been disabled. You may call the authentication() method."
|
|
1087
|
+
});
|
|
1073
1088
|
}
|
|
1074
1089
|
this.logger.info(`Silent authentication failed, falling back to interactive method.`);
|
|
1075
1090
|
return this.doGetToken(scopes, options);
|
|
@@ -1138,7 +1153,7 @@ function getPropertyFromVSCode(property) {
|
|
|
1138
1153
|
}
|
|
1139
1154
|
}
|
|
1140
1155
|
/**
|
|
1141
|
-
*
|
|
1156
|
+
* Connects to Azure using the credential provided by the VSCode extension 'Azure Account'.
|
|
1142
1157
|
* Once the user has logged in via the extension, this credential can share the same refresh token
|
|
1143
1158
|
* that is cached by the extension.
|
|
1144
1159
|
*/
|
|
@@ -1167,7 +1182,6 @@ class VisualStudioCodeCredential {
|
|
|
1167
1182
|
else {
|
|
1168
1183
|
this.tenantId = CommonTenantId;
|
|
1169
1184
|
}
|
|
1170
|
-
this.allowMultiTenantAuthentication = options === null || options === void 0 ? void 0 : options.allowMultiTenantAuthentication;
|
|
1171
1185
|
checkUnsupportedTenant(this.tenantId);
|
|
1172
1186
|
}
|
|
1173
1187
|
/**
|
|
@@ -1201,8 +1215,7 @@ class VisualStudioCodeCredential {
|
|
|
1201
1215
|
async getToken(scopes, options) {
|
|
1202
1216
|
var _a, _b;
|
|
1203
1217
|
await this.prepareOnce();
|
|
1204
|
-
const tenantId = processMultiTenantRequest(this.tenantId,
|
|
1205
|
-
this.tenantId;
|
|
1218
|
+
const tenantId = processMultiTenantRequest(this.tenantId, options) || this.tenantId;
|
|
1206
1219
|
if (findCredentials === undefined) {
|
|
1207
1220
|
throw new CredentialUnavailableError([
|
|
1208
1221
|
"No implementation of `VisualStudioCodeCredential` is available.",
|
|
@@ -1239,13 +1252,13 @@ class VisualStudioCodeCredential {
|
|
|
1239
1252
|
return tokenResponse.accessToken;
|
|
1240
1253
|
}
|
|
1241
1254
|
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?");
|
|
1255
|
+
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
1256
|
logger$1.getToken.info(formatError(scopes, error));
|
|
1244
1257
|
throw error;
|
|
1245
1258
|
}
|
|
1246
1259
|
}
|
|
1247
1260
|
else {
|
|
1248
|
-
const error = new CredentialUnavailableError("Could not retrieve the token associated with Visual Studio Code. Did you connect using the 'Azure Account' extension?");
|
|
1261
|
+
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
1262
|
logger$1.getToken.info(formatError(scopes, error));
|
|
1250
1263
|
throw error;
|
|
1251
1264
|
}
|
|
@@ -1340,7 +1353,7 @@ class ChainedTokenCredential {
|
|
|
1340
1353
|
let token = null;
|
|
1341
1354
|
let successfulCredentialName = "";
|
|
1342
1355
|
const errors = [];
|
|
1343
|
-
const { span, updatedOptions } = createSpan("ChainedTokenCredential
|
|
1356
|
+
const { span, updatedOptions } = createSpan("ChainedTokenCredential.getToken", options);
|
|
1344
1357
|
for (let i = 0; i < this._sources.length && token === null; i++) {
|
|
1345
1358
|
try {
|
|
1346
1359
|
token = await this._sources[i].getToken(scopes, updatedOptions);
|
|
@@ -1427,15 +1440,15 @@ const cliCredentialInternals = {
|
|
|
1427
1440
|
}
|
|
1428
1441
|
return new Promise((resolve, reject) => {
|
|
1429
1442
|
try {
|
|
1430
|
-
|
|
1443
|
+
child_process__default.execFile("az", [
|
|
1431
1444
|
"account",
|
|
1432
1445
|
"get-access-token",
|
|
1433
1446
|
"--output",
|
|
1434
1447
|
"json",
|
|
1435
1448
|
"--resource",
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
], { cwd: cliCredentialInternals.getSafeWorkingDir() }, (error, stdout, stderr) => {
|
|
1449
|
+
resource,
|
|
1450
|
+
...tenantSection
|
|
1451
|
+
], { cwd: cliCredentialInternals.getSafeWorkingDir(), shell: true }, (error, stdout, stderr) => {
|
|
1439
1452
|
resolve({ stdout: stdout, stderr: stderr, error });
|
|
1440
1453
|
});
|
|
1441
1454
|
}
|
|
@@ -1451,18 +1464,18 @@ const logger$3 = credentialLogger("AzureCliCredential");
|
|
|
1451
1464
|
* via the Azure CLI ('az') commandline tool.
|
|
1452
1465
|
* To do so, it will read the user access token and expire time
|
|
1453
1466
|
* 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
1467
|
*/
|
|
1457
1468
|
class AzureCliCredential {
|
|
1458
1469
|
/**
|
|
1459
1470
|
* Creates an instance of the {@link AzureCliCredential}.
|
|
1460
1471
|
*
|
|
1472
|
+
* To use this credential, ensure that you have already logged
|
|
1473
|
+
* in via the 'az' tool using the command "az login" from the commandline.
|
|
1474
|
+
*
|
|
1461
1475
|
* @param options - Options, to optionally allow multi-tenant requests.
|
|
1462
1476
|
*/
|
|
1463
1477
|
constructor(options) {
|
|
1464
1478
|
this.tenantId = options === null || options === void 0 ? void 0 : options.tenantId;
|
|
1465
|
-
this.allowMultiTenantAuthentication = options === null || options === void 0 ? void 0 : options.allowMultiTenantAuthentication;
|
|
1466
1479
|
}
|
|
1467
1480
|
/**
|
|
1468
1481
|
* Authenticates with Azure Active Directory and returns an access token if successful.
|
|
@@ -1473,7 +1486,7 @@ class AzureCliCredential {
|
|
|
1473
1486
|
* TokenCredential implementation might make.
|
|
1474
1487
|
*/
|
|
1475
1488
|
async getToken(scopes, options) {
|
|
1476
|
-
const tenantId = processMultiTenantRequest(this.tenantId,
|
|
1489
|
+
const tenantId = processMultiTenantRequest(this.tenantId, options);
|
|
1477
1490
|
if (tenantId) {
|
|
1478
1491
|
checkTenantId(logger$3, tenantId);
|
|
1479
1492
|
}
|
|
@@ -1482,7 +1495,7 @@ class AzureCliCredential {
|
|
|
1482
1495
|
ensureValidScope(scope, logger$3);
|
|
1483
1496
|
const resource = getScopeResource(scope);
|
|
1484
1497
|
let responseData = "";
|
|
1485
|
-
const { span } = createSpan("AzureCliCredential
|
|
1498
|
+
const { span } = createSpan("AzureCliCredential.getToken", options);
|
|
1486
1499
|
try {
|
|
1487
1500
|
const obj = await cliCredentialInternals.getAzureCliAccessToken(resource, tenantId);
|
|
1488
1501
|
if (obj.stderr) {
|
|
@@ -1599,7 +1612,8 @@ const powerShellErrors = {
|
|
|
1599
1612
|
*/
|
|
1600
1613
|
const powerShellPublicErrorMessages = {
|
|
1601
1614
|
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"
|
|
1615
|
+
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".`,
|
|
1616
|
+
troubleshoot: `To troubleshoot, visit https://aka.ms/azsdk/js/identity/powershellcredential/troubleshoot.`
|
|
1603
1617
|
};
|
|
1604
1618
|
// PowerShell Azure User not logged in error check.
|
|
1605
1619
|
const isLoginError = (err) => err.message.match(`(.*)${powerShellErrors.login}(.*)`);
|
|
@@ -1618,22 +1632,21 @@ if (isWindows) {
|
|
|
1618
1632
|
* This credential will use the currently logged-in user information from the
|
|
1619
1633
|
* Azure PowerShell module. To do so, it will read the user access token and
|
|
1620
1634
|
* 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
1635
|
*/
|
|
1628
1636
|
class AzurePowerShellCredential {
|
|
1629
1637
|
/**
|
|
1630
|
-
* Creates an instance of the {@link
|
|
1638
|
+
* Creates an instance of the {@link AzurePowerShellCredential}.
|
|
1639
|
+
*
|
|
1640
|
+
* To use this credential:
|
|
1641
|
+
* - Install the Azure Az PowerShell module with:
|
|
1642
|
+
* `Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force`.
|
|
1643
|
+
* - You have already logged in to Azure PowerShell using the command
|
|
1644
|
+
* `Connect-AzAccount` from the command line.
|
|
1631
1645
|
*
|
|
1632
1646
|
* @param options - Options, to optionally allow multi-tenant requests.
|
|
1633
1647
|
*/
|
|
1634
1648
|
constructor(options) {
|
|
1635
1649
|
this.tenantId = options === null || options === void 0 ? void 0 : options.tenantId;
|
|
1636
|
-
this.allowMultiTenantAuthentication = options === null || options === void 0 ? void 0 : options.allowMultiTenantAuthentication;
|
|
1637
1650
|
}
|
|
1638
1651
|
/**
|
|
1639
1652
|
* Gets the access token from Azure PowerShell
|
|
@@ -1674,7 +1687,7 @@ class AzurePowerShellCredential {
|
|
|
1674
1687
|
throw new Error(`Unable to parse the output of PowerShell. Received output: ${result}`);
|
|
1675
1688
|
}
|
|
1676
1689
|
}
|
|
1677
|
-
throw new Error(`Unable to execute PowerShell. Ensure that it is installed in your system
|
|
1690
|
+
throw new Error(`Unable to execute PowerShell. Ensure that it is installed in your system`);
|
|
1678
1691
|
}
|
|
1679
1692
|
/**
|
|
1680
1693
|
* Authenticates with Azure Active Directory and returns an access token if successful.
|
|
@@ -1685,7 +1698,7 @@ class AzurePowerShellCredential {
|
|
|
1685
1698
|
*/
|
|
1686
1699
|
async getToken(scopes, options = {}) {
|
|
1687
1700
|
return trace(`${this.constructor.name}.getToken`, options, async () => {
|
|
1688
|
-
const tenantId = processMultiTenantRequest(this.tenantId,
|
|
1701
|
+
const tenantId = processMultiTenantRequest(this.tenantId, options);
|
|
1689
1702
|
if (tenantId) {
|
|
1690
1703
|
checkTenantId(logger$4, tenantId);
|
|
1691
1704
|
}
|
|
@@ -1712,7 +1725,7 @@ class AzurePowerShellCredential {
|
|
|
1712
1725
|
logger$4.getToken.info(formatError(scope, error));
|
|
1713
1726
|
throw error;
|
|
1714
1727
|
}
|
|
1715
|
-
const error = new CredentialUnavailableError(err);
|
|
1728
|
+
const error = new CredentialUnavailableError(`${err}. ${powerShellPublicErrorMessages.troubleshoot}`);
|
|
1716
1729
|
logger$4.getToken.info(formatError(scope, error));
|
|
1717
1730
|
throw error;
|
|
1718
1731
|
}
|
|
@@ -1772,7 +1785,7 @@ class ClientSecretCredential {
|
|
|
1772
1785
|
*/
|
|
1773
1786
|
constructor(tenantId, clientId, clientSecret, options = {}) {
|
|
1774
1787
|
if (!tenantId || !clientId || !clientSecret) {
|
|
1775
|
-
throw new Error("ClientSecretCredential: tenantId, clientId, and clientSecret are required parameters.");
|
|
1788
|
+
throw new Error("ClientSecretCredential: tenantId, clientId, and clientSecret are required parameters. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.");
|
|
1776
1789
|
}
|
|
1777
1790
|
this.msalFlow = new MsalClientSecret(Object.assign(Object.assign({}, options), { logger: logger$5,
|
|
1778
1791
|
clientId,
|
|
@@ -1800,14 +1813,15 @@ const readFileAsync = util.promisify(fs.readFile);
|
|
|
1800
1813
|
/**
|
|
1801
1814
|
* Tries to asynchronously load a certificate from the given path.
|
|
1802
1815
|
*
|
|
1803
|
-
* @param
|
|
1816
|
+
* @param configuration - Either the PEM value or the path to the certificate.
|
|
1804
1817
|
* @param sendCertificateChain - Option to include x5c header for SubjectName and Issuer name authorization.
|
|
1805
1818
|
* @returns - The certificate parts, or `undefined` if the certificate could not be loaded.
|
|
1806
1819
|
* @internal
|
|
1807
1820
|
*/
|
|
1808
|
-
async function parseCertificate(
|
|
1821
|
+
async function parseCertificate(configuration, sendCertificateChain) {
|
|
1809
1822
|
const certificateParts = {};
|
|
1810
|
-
certificateParts.certificateContents =
|
|
1823
|
+
certificateParts.certificateContents =
|
|
1824
|
+
configuration.certificate || (await readFileAsync(configuration.certificatePath, "utf8"));
|
|
1811
1825
|
if (sendCertificateChain) {
|
|
1812
1826
|
certificateParts.x5c = certificateParts.certificateContents;
|
|
1813
1827
|
}
|
|
@@ -1838,13 +1852,13 @@ class MsalClientCertificate extends MsalNode {
|
|
|
1838
1852
|
constructor(options) {
|
|
1839
1853
|
super(options);
|
|
1840
1854
|
this.requiresConfidential = true;
|
|
1841
|
-
this.
|
|
1855
|
+
this.configuration = options.configuration;
|
|
1842
1856
|
this.sendCertificateChain = options.sendCertificateChain;
|
|
1843
1857
|
}
|
|
1844
1858
|
// Changing the MSAL configuration asynchronously
|
|
1845
1859
|
async init(options) {
|
|
1846
1860
|
try {
|
|
1847
|
-
const parts = await parseCertificate(this.
|
|
1861
|
+
const parts = await parseCertificate(this.configuration, this.sendCertificateChain);
|
|
1848
1862
|
this.msalConfig.auth.clientCertificate = {
|
|
1849
1863
|
thumbprint: parts.thumbprint,
|
|
1850
1864
|
privateKey: parts.certificateContents,
|
|
@@ -1877,7 +1891,8 @@ class MsalClientCertificate extends MsalNode {
|
|
|
1877
1891
|
}
|
|
1878
1892
|
|
|
1879
1893
|
// Copyright (c) Microsoft Corporation.
|
|
1880
|
-
const
|
|
1894
|
+
const credentialName = "ClientCertificateCredential";
|
|
1895
|
+
const logger$6 = credentialLogger(credentialName);
|
|
1881
1896
|
/**
|
|
1882
1897
|
* Enables authentication to Azure Active Directory using a PEM-encoded
|
|
1883
1898
|
* certificate that is assigned to an App Registration. More information
|
|
@@ -1887,20 +1902,22 @@ const logger$6 = credentialLogger("ClientCertificateCredential");
|
|
|
1887
1902
|
*
|
|
1888
1903
|
*/
|
|
1889
1904
|
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.");
|
|
1905
|
+
constructor(tenantId, clientId, certificatePathOrConfiguration, options = {}) {
|
|
1906
|
+
if (!tenantId || !clientId) {
|
|
1907
|
+
throw new Error(`${credentialName}: tenantId and clientId are required parameters.`);
|
|
1908
|
+
}
|
|
1909
|
+
const configuration = Object.assign({}, (typeof certificatePathOrConfiguration === "string"
|
|
1910
|
+
? {
|
|
1911
|
+
certificatePath: certificatePathOrConfiguration
|
|
1912
|
+
}
|
|
1913
|
+
: certificatePathOrConfiguration));
|
|
1914
|
+
if (!configuration || !(configuration.certificate || configuration.certificatePath)) {
|
|
1915
|
+
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
1916
|
}
|
|
1903
|
-
|
|
1917
|
+
if (configuration.certificate && configuration.certificatePath) {
|
|
1918
|
+
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.`);
|
|
1919
|
+
}
|
|
1920
|
+
this.msalFlow = new MsalClientCertificate(Object.assign(Object.assign({}, options), { configuration,
|
|
1904
1921
|
logger: logger$6,
|
|
1905
1922
|
clientId,
|
|
1906
1923
|
tenantId, sendCertificateChain: options.sendCertificateChain, tokenCredentialOptions: options }));
|
|
@@ -1914,7 +1931,7 @@ class ClientCertificateCredential {
|
|
|
1914
1931
|
* TokenCredential implementation might make.
|
|
1915
1932
|
*/
|
|
1916
1933
|
async getToken(scopes, options = {}) {
|
|
1917
|
-
return trace(`${
|
|
1934
|
+
return trace(`${credentialName}.getToken`, options, async (newOptions) => {
|
|
1918
1935
|
const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];
|
|
1919
1936
|
return this.msalFlow.getToken(arrayScopes, newOptions);
|
|
1920
1937
|
});
|
|
@@ -1958,8 +1975,6 @@ const logger$7 = credentialLogger("UsernamePasswordCredential");
|
|
|
1958
1975
|
* trust so you should only use it when other, more secure credential
|
|
1959
1976
|
* types can't be used.
|
|
1960
1977
|
*/
|
|
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
1978
|
class UsernamePasswordCredential {
|
|
1964
1979
|
/**
|
|
1965
1980
|
* Creates an instance of the UsernamePasswordCredential with the details
|
|
@@ -1974,7 +1989,7 @@ class UsernamePasswordCredential {
|
|
|
1974
1989
|
*/
|
|
1975
1990
|
constructor(tenantId, clientId, username, password, options = {}) {
|
|
1976
1991
|
if (!tenantId || !clientId || !username || !password) {
|
|
1977
|
-
throw new Error("UsernamePasswordCredential: tenantId, clientId, username and password are required parameters.");
|
|
1992
|
+
throw new Error("UsernamePasswordCredential: tenantId, clientId, username and password are required parameters. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.");
|
|
1978
1993
|
}
|
|
1979
1994
|
this.msalFlow = new MsalUsernamePassword(Object.assign(Object.assign({}, options), { logger: logger$7,
|
|
1980
1995
|
clientId,
|
|
@@ -2021,23 +2036,7 @@ const AllSupportedEnvironmentVariables = [
|
|
|
2021
2036
|
const logger$8 = credentialLogger("EnvironmentCredential");
|
|
2022
2037
|
/**
|
|
2023
2038
|
* 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.
|
|
2039
|
+
* details configured in environment variables
|
|
2041
2040
|
*/
|
|
2042
2041
|
class EnvironmentCredential {
|
|
2043
2042
|
/**
|
|
@@ -2077,7 +2076,7 @@ class EnvironmentCredential {
|
|
|
2077
2076
|
const certificatePath = process.env.AZURE_CLIENT_CERTIFICATE_PATH;
|
|
2078
2077
|
if (tenantId && clientId && certificatePath) {
|
|
2079
2078
|
logger$8.info(`Invoking ClientCertificateCredential with tenant ID: ${tenantId}, clientId: ${clientId} and certificatePath: ${certificatePath}`);
|
|
2080
|
-
this._credential = new ClientCertificateCredential(tenantId, clientId, certificatePath, options);
|
|
2079
|
+
this._credential = new ClientCertificateCredential(tenantId, clientId, { certificatePath }, options);
|
|
2081
2080
|
return;
|
|
2082
2081
|
}
|
|
2083
2082
|
const username = process.env.AZURE_USERNAME;
|
|
@@ -2103,7 +2102,7 @@ class EnvironmentCredential {
|
|
|
2103
2102
|
}
|
|
2104
2103
|
catch (err) {
|
|
2105
2104
|
const authenticationError = new AuthenticationError(400, {
|
|
2106
|
-
error: "EnvironmentCredential authentication failed.",
|
|
2105
|
+
error: "EnvironmentCredential authentication failed. To troubleshoot, visit https://aka.ms/azsdk/js/identity/environmentcredential/troubleshoot.",
|
|
2107
2106
|
error_description: err.message
|
|
2108
2107
|
.toString()
|
|
2109
2108
|
.split("More details:")
|
|
@@ -2113,7 +2112,7 @@ class EnvironmentCredential {
|
|
|
2113
2112
|
throw authenticationError;
|
|
2114
2113
|
}
|
|
2115
2114
|
}
|
|
2116
|
-
throw new CredentialUnavailableError("EnvironmentCredential is unavailable. No underlying credential could be used.");
|
|
2115
|
+
throw new CredentialUnavailableError("EnvironmentCredential is unavailable. No underlying credential could be used. To troubleshoot, visit https://aka.ms/azsdk/js/identity/environmentcredential/troubleshoot.");
|
|
2117
2116
|
});
|
|
2118
2117
|
}
|
|
2119
2118
|
}
|
|
@@ -2125,6 +2124,7 @@ const imdsHost = "http://169.254.169.254";
|
|
|
2125
2124
|
const imdsEndpointPath = "/metadata/identity/oauth2/token";
|
|
2126
2125
|
const imdsApiVersion = "2018-02-01";
|
|
2127
2126
|
const azureArcAPIVersion = "2019-11-01";
|
|
2127
|
+
const azureFabricVersion = "2019-07-01-preview";
|
|
2128
2128
|
|
|
2129
2129
|
// Copyright (c) Microsoft Corporation.
|
|
2130
2130
|
/**
|
|
@@ -2151,8 +2151,11 @@ function mapScopesToResource(scopes) {
|
|
|
2151
2151
|
}
|
|
2152
2152
|
return scope.substr(0, scope.lastIndexOf(DefaultScopeSuffix));
|
|
2153
2153
|
}
|
|
2154
|
-
async function msiGenericGetToken(identityClient, requestOptions, expiresInParser, getTokenOptions = {}) {
|
|
2154
|
+
async function msiGenericGetToken(identityClient, requestOptions, expiresInParser, getTokenOptions = {}, agent) {
|
|
2155
2155
|
const request = coreRestPipeline.createPipelineRequest(Object.assign(Object.assign({ abortSignal: getTokenOptions.abortSignal }, requestOptions), { allowInsecureConnection: true }));
|
|
2156
|
+
if (agent) {
|
|
2157
|
+
request.agent = agent;
|
|
2158
|
+
}
|
|
2156
2159
|
const tokenResponse = await identityClient.sendTokenRequest(request, expiresInParser);
|
|
2157
2160
|
return (tokenResponse && tokenResponse.accessToken) || null;
|
|
2158
2161
|
}
|
|
@@ -2274,7 +2277,7 @@ function expiresInParser$2(requestBody) {
|
|
|
2274
2277
|
if (requestBody.expires_on) {
|
|
2275
2278
|
// Use the expires_on timestamp if it's available
|
|
2276
2279
|
const expires = +requestBody.expires_on * 1000;
|
|
2277
|
-
logger$b.info(`${msiName$2}:
|
|
2280
|
+
logger$b.info(`${msiName$2}: Using expires_on: ${expires} (original value: ${requestBody.expires_on})`);
|
|
2278
2281
|
return expires;
|
|
2279
2282
|
}
|
|
2280
2283
|
else {
|
|
@@ -2284,29 +2287,41 @@ function expiresInParser$2(requestBody) {
|
|
|
2284
2287
|
return expires;
|
|
2285
2288
|
}
|
|
2286
2289
|
}
|
|
2287
|
-
function prepareRequestOptions$2(scopes, clientId) {
|
|
2290
|
+
function prepareRequestOptions$2(scopes, clientId, options) {
|
|
2288
2291
|
var _a;
|
|
2289
2292
|
const resource = mapScopesToResource(scopes);
|
|
2290
2293
|
if (!resource) {
|
|
2291
2294
|
throw new Error(`${msiName$2}: Multiple scopes are not supported.`);
|
|
2292
2295
|
}
|
|
2293
|
-
const
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
if (
|
|
2298
|
-
queryParameters
|
|
2296
|
+
const { skipQuery, skipMetadataHeader } = options || {};
|
|
2297
|
+
let query = "";
|
|
2298
|
+
// Pod Identity will try to process this request even if the Metadata header is missing.
|
|
2299
|
+
// We can exclude the request query to ensure no IMDS endpoint tries to process the ping request.
|
|
2300
|
+
if (!skipQuery) {
|
|
2301
|
+
const queryParameters = {
|
|
2302
|
+
resource,
|
|
2303
|
+
"api-version": imdsApiVersion
|
|
2304
|
+
};
|
|
2305
|
+
if (clientId) {
|
|
2306
|
+
queryParameters.client_id = clientId;
|
|
2307
|
+
}
|
|
2308
|
+
const params = new URLSearchParams(queryParameters);
|
|
2309
|
+
query = `?${params.toString()}`;
|
|
2299
2310
|
}
|
|
2300
|
-
const params = new URLSearchParams(queryParameters);
|
|
2301
|
-
const query = params.toString();
|
|
2302
2311
|
const url = new URL(imdsEndpointPath, (_a = process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST) !== null && _a !== void 0 ? _a : imdsHost);
|
|
2312
|
+
const rawHeaders = {
|
|
2313
|
+
Accept: "application/json",
|
|
2314
|
+
Metadata: "true"
|
|
2315
|
+
};
|
|
2316
|
+
// Remove the Metadata header to invoke a request error from some IMDS endpoints.
|
|
2317
|
+
if (skipMetadataHeader) {
|
|
2318
|
+
delete rawHeaders.Metadata;
|
|
2319
|
+
}
|
|
2303
2320
|
return {
|
|
2304
|
-
|
|
2321
|
+
// In this case, the `?` should be added in the "query" variable `skipQuery` is not set.
|
|
2322
|
+
url: `${url}${query}`,
|
|
2305
2323
|
method: "GET",
|
|
2306
|
-
headers: coreRestPipeline.createHttpHeaders(
|
|
2307
|
-
Accept: "application/json",
|
|
2308
|
-
Metadata: "true"
|
|
2309
|
-
})
|
|
2324
|
+
headers: coreRestPipeline.createHttpHeaders(rawHeaders)
|
|
2310
2325
|
};
|
|
2311
2326
|
}
|
|
2312
2327
|
// 800ms -> 1600ms -> 3200ms
|
|
@@ -2328,13 +2343,10 @@ const imdsMsi = {
|
|
|
2328
2343
|
if (process.env.AZURE_POD_IDENTITY_AUTHORITY_HOST) {
|
|
2329
2344
|
return true;
|
|
2330
2345
|
}
|
|
2331
|
-
const requestOptions = prepareRequestOptions$2(resource, clientId
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
// IMDS endpoint
|
|
2336
|
-
requestOptions.headers.delete("Metadata");
|
|
2337
|
-
}
|
|
2346
|
+
const requestOptions = prepareRequestOptions$2(resource, clientId, {
|
|
2347
|
+
skipMetadataHeader: true,
|
|
2348
|
+
skipQuery: true
|
|
2349
|
+
});
|
|
2338
2350
|
requestOptions.tracingOptions = options.tracingOptions;
|
|
2339
2351
|
try {
|
|
2340
2352
|
// Create a request with a timeout since we expect that
|
|
@@ -2566,7 +2578,84 @@ function tokenExchangeMsi() {
|
|
|
2566
2578
|
}
|
|
2567
2579
|
|
|
2568
2580
|
// Copyright (c) Microsoft Corporation.
|
|
2569
|
-
const
|
|
2581
|
+
const msiName$5 = "ManagedIdentityCredential - Fabric MSI";
|
|
2582
|
+
const logger$e = credentialLogger(msiName$5);
|
|
2583
|
+
function expiresInParser$5(requestBody) {
|
|
2584
|
+
// Parses a string representation of the seconds since epoch into a number value
|
|
2585
|
+
return Number(requestBody.expires_on);
|
|
2586
|
+
}
|
|
2587
|
+
function prepareRequestOptions$5(scopes, clientId) {
|
|
2588
|
+
const resource = mapScopesToResource(scopes);
|
|
2589
|
+
if (!resource) {
|
|
2590
|
+
throw new Error(`${msiName$5}: Multiple scopes are not supported.`);
|
|
2591
|
+
}
|
|
2592
|
+
const queryParameters = {
|
|
2593
|
+
resource,
|
|
2594
|
+
"api-version": azureFabricVersion
|
|
2595
|
+
};
|
|
2596
|
+
if (clientId) {
|
|
2597
|
+
queryParameters.client_id = clientId;
|
|
2598
|
+
}
|
|
2599
|
+
const query = new URLSearchParams(queryParameters);
|
|
2600
|
+
// This error should not bubble up, since we verify that this environment variable is defined in the isAvailable() method defined below.
|
|
2601
|
+
if (!process.env.IDENTITY_ENDPOINT) {
|
|
2602
|
+
throw new Error("Missing environment variable: IDENTITY_ENDPOINT");
|
|
2603
|
+
}
|
|
2604
|
+
if (!process.env.IDENTITY_HEADER) {
|
|
2605
|
+
throw new Error("Missing environment variable: IDENTITY_HEADER");
|
|
2606
|
+
}
|
|
2607
|
+
return {
|
|
2608
|
+
url: `${process.env.IDENTITY_ENDPOINT}?${query.toString()}`,
|
|
2609
|
+
method: "GET",
|
|
2610
|
+
headers: coreRestPipeline.createHttpHeaders({
|
|
2611
|
+
Accept: "application/json",
|
|
2612
|
+
Secret: process.env.IDENTITY_HEADER
|
|
2613
|
+
})
|
|
2614
|
+
};
|
|
2615
|
+
}
|
|
2616
|
+
// This credential can be easily tested by deploying a container to Azure Service Fabric with the Dockerfile:
|
|
2617
|
+
//
|
|
2618
|
+
// FROM node:12
|
|
2619
|
+
// RUN wget https://host.any/path/bash.sh
|
|
2620
|
+
// CMD ["bash", "bash.sh"]
|
|
2621
|
+
//
|
|
2622
|
+
// Where the bash script contains:
|
|
2623
|
+
//
|
|
2624
|
+
// curl --insecure $IDENTITY_ENDPOINT'?api-version=2019-07-01-preview&resource=https://vault.azure.net/' -H "Secret: $IDENTITY_HEADER"
|
|
2625
|
+
//
|
|
2626
|
+
const fabricMsi = {
|
|
2627
|
+
async isAvailable(scopes) {
|
|
2628
|
+
const resource = mapScopesToResource(scopes);
|
|
2629
|
+
if (!resource) {
|
|
2630
|
+
logger$e.info(`${msiName$5}: Unavailable. Multiple scopes are not supported.`);
|
|
2631
|
+
return false;
|
|
2632
|
+
}
|
|
2633
|
+
const env = process.env;
|
|
2634
|
+
const result = Boolean(env.IDENTITY_ENDPOINT && env.IDENTITY_HEADER && env.IDENTITY_SERVER_THUMBPRINT);
|
|
2635
|
+
if (!result) {
|
|
2636
|
+
logger$e.info(`${msiName$5}: Unavailable. The environment variables needed are: IDENTITY_ENDPOINT, IDENTITY_HEADER and IDENTITY_SERVER_THUMBPRINT`);
|
|
2637
|
+
}
|
|
2638
|
+
return result;
|
|
2639
|
+
},
|
|
2640
|
+
async getToken(configuration, getTokenOptions = {}) {
|
|
2641
|
+
const { scopes, identityClient, clientId } = configuration;
|
|
2642
|
+
logger$e.info([
|
|
2643
|
+
`${msiName$5}:`,
|
|
2644
|
+
"Using the endpoint and the secret coming from the environment variables:",
|
|
2645
|
+
`IDENTITY_ENDPOINT=${process.env.IDENTITY_ENDPOINT},`,
|
|
2646
|
+
"IDENTITY_HEADER=[REDACTED] and",
|
|
2647
|
+
"IDENTITY_SERVER_THUMBPRINT=[REDACTED]."
|
|
2648
|
+
].join(" "));
|
|
2649
|
+
return msiGenericGetToken(identityClient, prepareRequestOptions$5(scopes, clientId), expiresInParser$5, getTokenOptions, new https.Agent({
|
|
2650
|
+
// This is necessary because Service Fabric provides a self-signed certificate.
|
|
2651
|
+
// The alternative path is to verify the certificate using the IDENTITY_SERVER_THUMBPRINT env variable.
|
|
2652
|
+
rejectUnauthorized: false
|
|
2653
|
+
}));
|
|
2654
|
+
}
|
|
2655
|
+
};
|
|
2656
|
+
|
|
2657
|
+
// Copyright (c) Microsoft Corporation.
|
|
2658
|
+
const logger$f = credentialLogger("ManagedIdentityCredential");
|
|
2570
2659
|
/**
|
|
2571
2660
|
* Attempts authentication using a managed identity that has been assigned
|
|
2572
2661
|
* to the deployment environment. This authentication type works in Azure VMs,
|
|
@@ -2597,9 +2686,7 @@ class ManagedIdentityCredential {
|
|
|
2597
2686
|
if (this.cachedMSI) {
|
|
2598
2687
|
return this.cachedMSI;
|
|
2599
2688
|
}
|
|
2600
|
-
|
|
2601
|
-
// which is necessary since Service Fabric only provides self-signed certificates on their Identity Endpoint.
|
|
2602
|
-
const MSIs = [appServiceMsi2017, cloudShellMsi, arcMsi, tokenExchangeMsi(), imdsMsi];
|
|
2689
|
+
const MSIs = [fabricMsi, appServiceMsi2017, cloudShellMsi, arcMsi, tokenExchangeMsi(), imdsMsi];
|
|
2603
2690
|
for (const msi of MSIs) {
|
|
2604
2691
|
if (await msi.isAvailable(scopes, this.identityClient, clientId, getTokenOptions)) {
|
|
2605
2692
|
this.cachedMSI = msi;
|
|
@@ -2641,7 +2728,7 @@ class ManagedIdentityCredential {
|
|
|
2641
2728
|
*/
|
|
2642
2729
|
async getToken(scopes, options) {
|
|
2643
2730
|
let result = null;
|
|
2644
|
-
const { span, updatedOptions } = createSpan("ManagedIdentityCredential
|
|
2731
|
+
const { span, updatedOptions } = createSpan("ManagedIdentityCredential.getToken", options);
|
|
2645
2732
|
try {
|
|
2646
2733
|
// isEndpointAvailable can be true, false, or null,
|
|
2647
2734
|
// If it's null, it means we don't yet know whether
|
|
@@ -2656,7 +2743,7 @@ class ManagedIdentityCredential {
|
|
|
2656
2743
|
// It also means that the endpoint answered with either 200 or 201 (see the sendTokenRequest method),
|
|
2657
2744
|
// yet we had no access token. For this reason, we'll throw once with a specific message:
|
|
2658
2745
|
const error = new CredentialUnavailableError("The managed identity endpoint was reached, yet no tokens were received.");
|
|
2659
|
-
logger$
|
|
2746
|
+
logger$f.getToken.info(formatError(scopes, error));
|
|
2660
2747
|
throw error;
|
|
2661
2748
|
}
|
|
2662
2749
|
// Since `authenticateManagedIdentity` didn't throw, and the result was not null,
|
|
@@ -2668,10 +2755,10 @@ class ManagedIdentityCredential {
|
|
|
2668
2755
|
// We've previously determined that the endpoint was unavailable,
|
|
2669
2756
|
// either because it was unreachable or permanently unable to authenticate.
|
|
2670
2757
|
const error = new CredentialUnavailableError("The managed identity endpoint is not currently available");
|
|
2671
|
-
logger$
|
|
2758
|
+
logger$f.getToken.info(formatError(scopes, error));
|
|
2672
2759
|
throw error;
|
|
2673
2760
|
}
|
|
2674
|
-
logger$
|
|
2761
|
+
logger$f.getToken.info(formatSuccess(scopes));
|
|
2675
2762
|
return result;
|
|
2676
2763
|
}
|
|
2677
2764
|
catch (err) {
|
|
@@ -2693,14 +2780,14 @@ class ManagedIdentityCredential {
|
|
|
2693
2780
|
// we can safely assume the credential is unavailable.
|
|
2694
2781
|
if (err.code === "ENETUNREACH") {
|
|
2695
2782
|
const error = new CredentialUnavailableError(`ManagedIdentityCredential is unavailable. Network unreachable. Message: ${err.message}`);
|
|
2696
|
-
logger$
|
|
2783
|
+
logger$f.getToken.info(formatError(scopes, error));
|
|
2697
2784
|
throw error;
|
|
2698
2785
|
}
|
|
2699
2786
|
// If either the host was unreachable,
|
|
2700
2787
|
// we can safely assume the credential is unavailable.
|
|
2701
2788
|
if (err.code === "EHOSTUNREACH") {
|
|
2702
2789
|
const error = new CredentialUnavailableError(`ManagedIdentityCredential is unavailable. No managed identity endpoint found. Message: ${err.message}`);
|
|
2703
|
-
logger$
|
|
2790
|
+
logger$f.getToken.info(formatError(scopes, error));
|
|
2704
2791
|
throw error;
|
|
2705
2792
|
}
|
|
2706
2793
|
// If err.statusCode has a value of 400, it comes from sendTokenRequest,
|
|
@@ -2754,22 +2841,26 @@ const defaultCredentials = [
|
|
|
2754
2841
|
];
|
|
2755
2842
|
/**
|
|
2756
2843
|
* 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.
|
|
2844
|
+
* work for most applications that use the Azure SDK.
|
|
2768
2845
|
*/
|
|
2769
2846
|
class DefaultAzureCredential extends ChainedTokenCredential {
|
|
2770
2847
|
/**
|
|
2771
2848
|
* Creates an instance of the DefaultAzureCredential class.
|
|
2772
2849
|
*
|
|
2850
|
+
* This credential provides a default {@link ChainedTokenCredential} configuration that should
|
|
2851
|
+
* work for most applications that use the Azure SDK.
|
|
2852
|
+
*
|
|
2853
|
+
* The following credential types will be tried, in order:
|
|
2854
|
+
*
|
|
2855
|
+
* - {@link EnvironmentCredential}
|
|
2856
|
+
* - {@link ManagedIdentityCredential}
|
|
2857
|
+
* - {@link VisualStudioCodeCredential}
|
|
2858
|
+
* - {@link AzureCliCredential}
|
|
2859
|
+
* - {@link AzurePowerShellCredential}
|
|
2860
|
+
*
|
|
2861
|
+
* Consult the documentation of these credential types for more information
|
|
2862
|
+
* on how they attempt authentication.
|
|
2863
|
+
*
|
|
2773
2864
|
* **Note**: `VisualStudioCodeCredential` is provided by a plugin package:
|
|
2774
2865
|
* `@azure/identity-vscode`. If this package is not installed and registered
|
|
2775
2866
|
* using the plugin API (`useIdentityPlugin`), then authentication using
|
|
@@ -2780,7 +2871,7 @@ class DefaultAzureCredential extends ChainedTokenCredential {
|
|
|
2780
2871
|
constructor(options) {
|
|
2781
2872
|
super(...defaultCredentials.map((ctor) => new ctor(options)));
|
|
2782
2873
|
this.UnavailableMessage =
|
|
2783
|
-
"DefaultAzureCredential => failed to retrieve a token from the included credentials";
|
|
2874
|
+
"DefaultAzureCredential => failed to retrieve a token from the included credentials. To troubleshoot, visit https://aka.ms/azsdk/js/identity/defaultazurecredential/troubleshoot.";
|
|
2784
2875
|
}
|
|
2785
2876
|
}
|
|
2786
2877
|
|
|
@@ -2928,29 +3019,29 @@ class MsalOpenBrowser extends MsalNode {
|
|
|
2928
3019
|
}
|
|
2929
3020
|
|
|
2930
3021
|
// Copyright (c) Microsoft Corporation.
|
|
2931
|
-
const logger$
|
|
3022
|
+
const logger$g = credentialLogger("InteractiveBrowserCredential");
|
|
2932
3023
|
/**
|
|
2933
3024
|
* Enables authentication to Azure Active Directory inside of the web browser
|
|
2934
3025
|
* 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
3026
|
*/
|
|
2943
3027
|
class InteractiveBrowserCredential {
|
|
2944
3028
|
/**
|
|
2945
3029
|
* Creates an instance of InteractiveBrowserCredential with the details needed.
|
|
2946
3030
|
*
|
|
3031
|
+
* This credential uses the [Authorization Code Flow](https://docs.microsoft.com/azure/active-directory/develop/v2-oauth2-auth-code-flow).
|
|
3032
|
+
* On Node.js, it will open a browser window while it listens for a redirect response from the authentication service.
|
|
3033
|
+
* 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.
|
|
3034
|
+
*
|
|
3035
|
+
* 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.
|
|
3036
|
+
* 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).
|
|
3037
|
+
*
|
|
2947
3038
|
* @param options - Options for configuring the client which makes the authentication requests.
|
|
2948
3039
|
*/
|
|
2949
3040
|
constructor(options = {}) {
|
|
2950
3041
|
const redirectUri = typeof options.redirectUri === "function"
|
|
2951
3042
|
? options.redirectUri()
|
|
2952
3043
|
: options.redirectUri || "http://localhost";
|
|
2953
|
-
this.msalFlow = new MsalOpenBrowser(Object.assign(Object.assign({}, options), { tokenCredentialOptions: options, logger: logger$
|
|
3044
|
+
this.msalFlow = new MsalOpenBrowser(Object.assign(Object.assign({}, options), { tokenCredentialOptions: options, logger: logger$g,
|
|
2954
3045
|
redirectUri }));
|
|
2955
3046
|
this.disableAutomaticAuthentication = options === null || options === void 0 ? void 0 : options.disableAutomaticAuthentication;
|
|
2956
3047
|
}
|
|
@@ -3028,7 +3119,7 @@ class MsalDeviceCode extends MsalNode {
|
|
|
3028
3119
|
}
|
|
3029
3120
|
|
|
3030
3121
|
// Copyright (c) Microsoft Corporation.
|
|
3031
|
-
const logger$
|
|
3122
|
+
const logger$h = credentialLogger("DeviceCodeCredential");
|
|
3032
3123
|
/**
|
|
3033
3124
|
* Method that logs the user code from the DeviceCodeCredential.
|
|
3034
3125
|
* @param deviceCodeInfo - The device code.
|
|
@@ -3045,10 +3136,24 @@ class DeviceCodeCredential {
|
|
|
3045
3136
|
* Creates an instance of DeviceCodeCredential with the details needed
|
|
3046
3137
|
* to initiate the device code authorization flow with Azure Active Directory.
|
|
3047
3138
|
*
|
|
3139
|
+
* A message will be logged, giving users a code that they can use to authenticate once they go to https://microsoft.com/devicelogin
|
|
3140
|
+
*
|
|
3141
|
+
* Developers can configure how this message is shown by passing a custom `userPromptCallback`:
|
|
3142
|
+
*
|
|
3143
|
+
* ```js
|
|
3144
|
+
* const credential = new DeviceCodeCredential({
|
|
3145
|
+
* tenantId: env.AZURE_TENANT_ID,
|
|
3146
|
+
* clientId: env.AZURE_CLIENT_ID,
|
|
3147
|
+
* userPromptCallback: (info) => {
|
|
3148
|
+
* console.log("CUSTOMIZED PROMPT CALLBACK", info.message);
|
|
3149
|
+
* }
|
|
3150
|
+
* });
|
|
3151
|
+
* ```
|
|
3152
|
+
*
|
|
3048
3153
|
* @param options - Options for configuring the client which makes the authentication requests.
|
|
3049
3154
|
*/
|
|
3050
3155
|
constructor(options) {
|
|
3051
|
-
this.msalFlow = new MsalDeviceCode(Object.assign(Object.assign({}, options), { logger: logger$
|
|
3156
|
+
this.msalFlow = new MsalDeviceCode(Object.assign(Object.assign({}, options), { logger: logger$h, userPromptCallback: (options === null || options === void 0 ? void 0 : options.userPromptCallback) || defaultDeviceCodePromptCallback, tokenCredentialOptions: options || {} }));
|
|
3052
3157
|
this.disableAutomaticAuthentication = options === null || options === void 0 ? void 0 : options.disableAutomaticAuthentication;
|
|
3053
3158
|
}
|
|
3054
3159
|
/**
|
|
@@ -3097,7 +3202,7 @@ class DeviceCodeCredential {
|
|
|
3097
3202
|
class MsalAuthorizationCode extends MsalNode {
|
|
3098
3203
|
constructor(options) {
|
|
3099
3204
|
super(options);
|
|
3100
|
-
this.logger = credentialLogger("
|
|
3205
|
+
this.logger = credentialLogger("Node.js MSAL Authorization Code");
|
|
3101
3206
|
this.redirectUri = options.redirectUri;
|
|
3102
3207
|
this.authorizationCode = options.authorizationCode;
|
|
3103
3208
|
if (options.clientSecret) {
|
|
@@ -3127,7 +3232,7 @@ class MsalAuthorizationCode extends MsalNode {
|
|
|
3127
3232
|
}
|
|
3128
3233
|
|
|
3129
3234
|
// Copyright (c) Microsoft Corporation.
|
|
3130
|
-
const logger$
|
|
3235
|
+
const logger$i = credentialLogger("AuthorizationCodeCredential");
|
|
3131
3236
|
/**
|
|
3132
3237
|
* Enables authentication to Azure Active Directory using an authorization code
|
|
3133
3238
|
* that was obtained through the authorization code flow, described in more detail
|
|
@@ -3141,7 +3246,7 @@ class AuthorizationCodeCredential {
|
|
|
3141
3246
|
* @internal
|
|
3142
3247
|
*/
|
|
3143
3248
|
constructor(tenantId, clientId, clientSecretOrAuthorizationCode, authorizationCodeOrRedirectUri, redirectUriOrOptions, options) {
|
|
3144
|
-
checkTenantId(logger$
|
|
3249
|
+
checkTenantId(logger$i, tenantId);
|
|
3145
3250
|
let clientSecret = clientSecretOrAuthorizationCode;
|
|
3146
3251
|
if (typeof redirectUriOrOptions === "string") {
|
|
3147
3252
|
// the clientId+clientSecret constructor
|
|
@@ -3157,7 +3262,7 @@ class AuthorizationCodeCredential {
|
|
|
3157
3262
|
options = redirectUriOrOptions;
|
|
3158
3263
|
}
|
|
3159
3264
|
this.msalFlow = new MsalAuthorizationCode(Object.assign(Object.assign({}, options), { clientSecret,
|
|
3160
|
-
clientId, tokenCredentialOptions: options || {}, logger: logger$
|
|
3265
|
+
clientId, tokenCredentialOptions: options || {}, logger: logger$i, redirectUri: this.redirectUri, authorizationCode: this.authorizationCode }));
|
|
3161
3266
|
}
|
|
3162
3267
|
/**
|
|
3163
3268
|
* Authenticates with Azure Active Directory and returns an access token if successful.
|
|
@@ -3175,36 +3280,6 @@ class AuthorizationCodeCredential {
|
|
|
3175
3280
|
}
|
|
3176
3281
|
}
|
|
3177
3282
|
|
|
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
3283
|
// Copyright (c) Microsoft Corporation.
|
|
3209
3284
|
/**
|
|
3210
3285
|
* MSAL on behalf of flow. Calls to MSAL's confidential application's `acquireTokenOnBehalfOf` during `doGetToken`.
|
|
@@ -3224,7 +3299,7 @@ class MsalOnBehalfOf extends MsalNode {
|
|
|
3224
3299
|
async init(options) {
|
|
3225
3300
|
if (this.certificatePath) {
|
|
3226
3301
|
try {
|
|
3227
|
-
const parts = await parseCertificate(this.certificatePath, this.sendCertificateChain);
|
|
3302
|
+
const parts = await parseCertificate({ certificatePath: this.certificatePath }, this.sendCertificateChain);
|
|
3228
3303
|
this.msalConfig.auth.clientCertificate = {
|
|
3229
3304
|
thumbprint: parts.thumbprint,
|
|
3230
3305
|
privateKey: parts.certificateContents,
|
|
@@ -3258,8 +3333,8 @@ class MsalOnBehalfOf extends MsalNode {
|
|
|
3258
3333
|
}
|
|
3259
3334
|
|
|
3260
3335
|
// Copyright (c) Microsoft Corporation.
|
|
3261
|
-
const credentialName = "OnBehalfOfCredential";
|
|
3262
|
-
const logger$
|
|
3336
|
+
const credentialName$1 = "OnBehalfOfCredential";
|
|
3337
|
+
const logger$j = credentialLogger(credentialName$1);
|
|
3263
3338
|
/**
|
|
3264
3339
|
* 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
3340
|
*/
|
|
@@ -3283,22 +3358,17 @@ class OnBehalfOfCredential {
|
|
|
3283
3358
|
* await client.getKey("key-name");
|
|
3284
3359
|
* ```
|
|
3285
3360
|
*
|
|
3286
|
-
* @param configuration - Configuration specific to this credential.
|
|
3287
3361
|
* @param options - Optional parameters, generally common across credentials.
|
|
3288
3362
|
*/
|
|
3289
|
-
constructor(
|
|
3290
|
-
this.configuration = configuration;
|
|
3363
|
+
constructor(options) {
|
|
3291
3364
|
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.`);
|
|
3365
|
+
const { clientSecret } = options;
|
|
3366
|
+
const { certificatePath } = options;
|
|
3367
|
+
const { tenantId, clientId, userAssertionToken } = options;
|
|
3368
|
+
if (!tenantId || !clientId || !(clientSecret || certificatePath) || !userAssertionToken) {
|
|
3369
|
+
throw new Error(`${credentialName$1}: tenantId, clientId, clientSecret (or certificatePath) and userAssertionToken are required parameters.`);
|
|
3300
3370
|
}
|
|
3301
|
-
this.msalFlow = new MsalOnBehalfOf(Object.assign(Object.assign(
|
|
3371
|
+
this.msalFlow = new MsalOnBehalfOf(Object.assign(Object.assign({}, this.options), { logger: logger$j, tokenCredentialOptions: this.options }));
|
|
3302
3372
|
}
|
|
3303
3373
|
/**
|
|
3304
3374
|
* Authenticates with Azure Active Directory and returns an access token if successful.
|
|
@@ -3308,7 +3378,7 @@ class OnBehalfOfCredential {
|
|
|
3308
3378
|
* @param options - The options used to configure the underlying network requests.
|
|
3309
3379
|
*/
|
|
3310
3380
|
async getToken(scopes, options = {}) {
|
|
3311
|
-
return trace(`${credentialName}.getToken`, options, async (newOptions) => {
|
|
3381
|
+
return trace(`${credentialName$1}.getToken`, options, async (newOptions) => {
|
|
3312
3382
|
const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];
|
|
3313
3383
|
return this.msalFlow.getToken(arrayScopes, newOptions);
|
|
3314
3384
|
});
|
|
@@ -3325,7 +3395,6 @@ function getDefaultAzureCredential() {
|
|
|
3325
3395
|
|
|
3326
3396
|
exports.AggregateAuthenticationError = AggregateAuthenticationError;
|
|
3327
3397
|
exports.AggregateAuthenticationErrorName = AggregateAuthenticationErrorName;
|
|
3328
|
-
exports.ApplicationCredential = ApplicationCredential;
|
|
3329
3398
|
exports.AuthenticationError = AuthenticationError;
|
|
3330
3399
|
exports.AuthenticationErrorName = AuthenticationErrorName;
|
|
3331
3400
|
exports.AuthenticationRequiredError = AuthenticationRequiredError;
|