@azure/identity 4.5.0-beta.1 → 4.5.0-beta.3
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +67 -50
- package/dist/index.js +355 -170
- package/dist/index.js.map +1 -1
- package/dist-esm/src/client/identityClient.js +4 -4
- package/dist-esm/src/client/identityClient.js.map +1 -1
- package/dist-esm/src/constants.js +2 -2
- package/dist-esm/src/constants.js.map +1 -1
- package/dist-esm/src/credentials/authorityValidationOptions.js +1 -1
- package/dist-esm/src/credentials/authorityValidationOptions.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/authorizationCodeCredential.js +1 -1
- package/dist-esm/src/credentials/authorizationCodeCredential.js.map +1 -1
- package/dist-esm/src/credentials/authorizationCodeCredentialOptions.js +1 -1
- package/dist-esm/src/credentials/authorizationCodeCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/azureApplicationCredential.browser.js +1 -1
- package/dist-esm/src/credentials/azureApplicationCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/azureApplicationCredential.js +1 -1
- package/dist-esm/src/credentials/azureApplicationCredential.js.map +1 -1
- package/dist-esm/src/credentials/azureApplicationCredentialOptions.js +1 -1
- package/dist-esm/src/credentials/azureApplicationCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/azureCliCredential.browser.js +1 -1
- package/dist-esm/src/credentials/azureCliCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/azureCliCredential.js +1 -1
- package/dist-esm/src/credentials/azureCliCredential.js.map +1 -1
- package/dist-esm/src/credentials/azureCliCredentialOptions.js +1 -1
- package/dist-esm/src/credentials/azureCliCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/azureDeveloperCliCredential.browser.js +1 -1
- package/dist-esm/src/credentials/azureDeveloperCliCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/azureDeveloperCliCredential.js +1 -1
- package/dist-esm/src/credentials/azureDeveloperCliCredential.js.map +1 -1
- package/dist-esm/src/credentials/azureDeveloperCliCredentialOptions.js +1 -1
- package/dist-esm/src/credentials/azureDeveloperCliCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/azurePipelinesCredential.browser.js +1 -1
- package/dist-esm/src/credentials/azurePipelinesCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/azurePipelinesCredential.js +51 -27
- package/dist-esm/src/credentials/azurePipelinesCredential.js.map +1 -1
- package/dist-esm/src/credentials/azurePipelinesCredentialOptions.js +1 -1
- package/dist-esm/src/credentials/azurePipelinesCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/azurePowerShellCredential.browser.js +1 -1
- package/dist-esm/src/credentials/azurePowerShellCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/azurePowerShellCredential.js +64 -20
- package/dist-esm/src/credentials/azurePowerShellCredential.js.map +1 -1
- package/dist-esm/src/credentials/azurePowerShellCredentialOptions.js +1 -1
- package/dist-esm/src/credentials/azurePowerShellCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/brokerAuthOptions.js.map +1 -1
- package/dist-esm/src/credentials/browserCustomizationOptions.js +1 -1
- package/dist-esm/src/credentials/browserCustomizationOptions.js.map +1 -1
- package/dist-esm/src/credentials/chainedTokenCredential.js +1 -1
- package/dist-esm/src/credentials/chainedTokenCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientAssertionCredential.browser.js +1 -1
- package/dist-esm/src/credentials/clientAssertionCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/clientAssertionCredential.js +10 -3
- package/dist-esm/src/credentials/clientAssertionCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientAssertionCredentialOptions.js +1 -1
- package/dist-esm/src/credentials/clientAssertionCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/clientCertificateCredential.browser.js +1 -1
- package/dist-esm/src/credentials/clientCertificateCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/clientCertificateCredential.js +36 -28
- package/dist-esm/src/credentials/clientCertificateCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientCertificateCredentialOptions.js +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 +10 -3
- package/dist-esm/src/credentials/clientSecretCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientSecretCredentialOptions.js +1 -1
- package/dist-esm/src/credentials/clientSecretCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/credentialPersistenceOptions.js +1 -1
- package/dist-esm/src/credentials/credentialPersistenceOptions.js.map +1 -1
- package/dist-esm/src/credentials/defaultAzureCredential.browser.js +1 -1
- package/dist-esm/src/credentials/defaultAzureCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/defaultAzureCredential.js +1 -1
- package/dist-esm/src/credentials/defaultAzureCredential.js.map +1 -1
- package/dist-esm/src/credentials/defaultAzureCredentialOptions.js +1 -1
- package/dist-esm/src/credentials/defaultAzureCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/deviceCodeCredential.browser.js +1 -1
- package/dist-esm/src/credentials/deviceCodeCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/deviceCodeCredential.js +2 -2
- package/dist-esm/src/credentials/deviceCodeCredential.js.map +1 -1
- package/dist-esm/src/credentials/deviceCodeCredentialOptions.js +1 -1
- package/dist-esm/src/credentials/deviceCodeCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/environmentCredential.browser.js +1 -1
- package/dist-esm/src/credentials/environmentCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/environmentCredential.js +12 -2
- package/dist-esm/src/credentials/environmentCredential.js.map +1 -1
- package/dist-esm/src/credentials/environmentCredentialOptions.js +1 -1
- package/dist-esm/src/credentials/environmentCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredential.js +2 -2
- package/dist-esm/src/credentials/interactiveBrowserCredential.js.map +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredentialOptions.js +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/interactiveCredentialOptions.js +1 -1
- package/dist-esm/src/credentials/interactiveCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2017.js +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2017.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2019.js +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2019.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/cloudShellMsi.js +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/cloudShellMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/constants.js +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/constants.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/fabricMsi.js +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/fabricMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/imdsMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/imdsRetryPolicy.js +6 -10
- package/dist-esm/src/credentials/managedIdentityCredential/imdsRetryPolicy.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/index.browser.js +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/index.browser.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/index.js +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/legacyMsiProvider.js +7 -1
- package/dist-esm/src/credentials/managedIdentityCredential/legacyMsiProvider.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/models.js +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/models.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/msalMsiProvider.js +25 -8
- package/dist-esm/src/credentials/managedIdentityCredential/msalMsiProvider.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/tokenExchangeMsi.js +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/utils.js +26 -1
- package/dist-esm/src/credentials/managedIdentityCredential/utils.js.map +1 -1
- package/dist-esm/src/credentials/multiTenantTokenCredentialOptions.js +1 -1
- package/dist-esm/src/credentials/multiTenantTokenCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/onBehalfOfCredential.browser.js +1 -1
- package/dist-esm/src/credentials/onBehalfOfCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/onBehalfOfCredential.js +17 -10
- package/dist-esm/src/credentials/onBehalfOfCredential.js.map +1 -1
- package/dist-esm/src/credentials/onBehalfOfCredentialOptions.js +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 +14 -4
- package/dist-esm/src/credentials/usernamePasswordCredential.js.map +1 -1
- package/dist-esm/src/credentials/usernamePasswordCredentialOptions.js +1 -1
- package/dist-esm/src/credentials/usernamePasswordCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/visualStudioCodeCredential.browser.js +1 -1
- package/dist-esm/src/credentials/visualStudioCodeCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/visualStudioCodeCredential.js +1 -1
- package/dist-esm/src/credentials/visualStudioCodeCredential.js.map +1 -1
- package/dist-esm/src/credentials/visualStudioCodeCredentialOptions.js +1 -1
- package/dist-esm/src/credentials/visualStudioCodeCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/visualStudioCodeCredentialPlugin.js +1 -1
- package/dist-esm/src/credentials/visualStudioCodeCredentialPlugin.js.map +1 -1
- package/dist-esm/src/credentials/workloadIdentityCredential.browser.js +1 -1
- package/dist-esm/src/credentials/workloadIdentityCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/workloadIdentityCredential.js +17 -7
- package/dist-esm/src/credentials/workloadIdentityCredential.js.map +1 -1
- package/dist-esm/src/credentials/workloadIdentityCredentialOptions.js +1 -1
- package/dist-esm/src/credentials/workloadIdentityCredentialOptions.js.map +1 -1
- package/dist-esm/src/errors.js +13 -9
- package/dist-esm/src/errors.js.map +1 -1
- package/dist-esm/src/index.js +1 -1
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/msal/browserFlows/flows.js +4 -0
- package/dist-esm/src/msal/browserFlows/flows.js.map +1 -0
- package/dist-esm/src/msal/browserFlows/msalAuthCode.js +1 -1
- package/dist-esm/src/msal/browserFlows/msalAuthCode.js.map +1 -1
- package/dist-esm/src/msal/browserFlows/msalBrowserCommon.js +3 -1
- package/dist-esm/src/msal/browserFlows/msalBrowserCommon.js.map +1 -1
- package/dist-esm/src/msal/credentials.js +1 -1
- package/dist-esm/src/msal/credentials.js.map +1 -1
- package/dist-esm/src/msal/msal.browser.js +1 -1
- package/dist-esm/src/msal/msal.browser.js.map +1 -1
- package/dist-esm/src/msal/msal.js +1 -1
- package/dist-esm/src/msal/msal.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/brokerOptions.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalClient.js +25 -9
- package/dist-esm/src/msal/nodeFlows/msalClient.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalPlugins.js +1 -1
- package/dist-esm/src/msal/nodeFlows/msalPlugins.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/tokenCachePersistenceOptions.js +1 -1
- package/dist-esm/src/msal/nodeFlows/tokenCachePersistenceOptions.js.map +1 -1
- package/dist-esm/src/msal/types.js +1 -1
- package/dist-esm/src/msal/types.js.map +1 -1
- package/dist-esm/src/msal/utils.js +15 -2
- package/dist-esm/src/msal/utils.js.map +1 -1
- package/dist-esm/src/plugins/consumer.browser.js +1 -1
- package/dist-esm/src/plugins/consumer.browser.js.map +1 -1
- package/dist-esm/src/plugins/consumer.js +1 -1
- package/dist-esm/src/plugins/consumer.js.map +1 -1
- package/dist-esm/src/plugins/provider.js +1 -1
- package/dist-esm/src/plugins/provider.js.map +1 -1
- package/dist-esm/src/regionalAuthority.js +1 -1
- package/dist-esm/src/regionalAuthority.js.map +1 -1
- package/dist-esm/src/tokenCredentialOptions.js +1 -1
- package/dist-esm/src/tokenCredentialOptions.js.map +1 -1
- package/dist-esm/src/tokenProvider.js +1 -1
- package/dist-esm/src/tokenProvider.js.map +1 -1
- package/dist-esm/src/util/authHostEnv.browser.js +1 -1
- package/dist-esm/src/util/authHostEnv.browser.js.map +1 -1
- package/dist-esm/src/util/identityTokenEndpoint.js +1 -1
- package/dist-esm/src/util/identityTokenEndpoint.js.map +1 -1
- package/dist-esm/src/util/logging.js +1 -1
- package/dist-esm/src/util/logging.js.map +1 -1
- package/dist-esm/src/util/processMultiTenantRequest.browser.js +1 -1
- package/dist-esm/src/util/processMultiTenantRequest.browser.js.map +1 -1
- package/dist-esm/src/util/processMultiTenantRequest.js +1 -1
- package/dist-esm/src/util/processMultiTenantRequest.js.map +1 -1
- package/dist-esm/src/util/processUtils.js +1 -1
- package/dist-esm/src/util/processUtils.js.map +1 -1
- package/dist-esm/src/util/scopeUtils.js +1 -1
- package/dist-esm/src/util/scopeUtils.js.map +1 -1
- package/dist-esm/src/util/tenantIdUtils.js +1 -1
- package/dist-esm/src/util/tenantIdUtils.js.map +1 -1
- package/dist-esm/src/util/tracing.js +1 -1
- package/dist-esm/src/util/tracing.js.map +1 -1
- package/package.json +9 -9
- package/types/identity.d.ts +47 -11
- package/dist-esm/src/msal/flows.js +0 -4
- package/dist-esm/src/msal/flows.js.map +0 -1
- package/dist-esm/src/msal/nodeFlows/msalAuthorizationCode.js +0 -47
- package/dist-esm/src/msal/nodeFlows/msalAuthorizationCode.js.map +0 -1
- package/dist-esm/src/msal/nodeFlows/msalClientAssertion.js +0 -42
- package/dist-esm/src/msal/nodeFlows/msalClientAssertion.js.map +0 -1
- package/dist-esm/src/msal/nodeFlows/msalClientCertificate.js +0 -112
- package/dist-esm/src/msal/nodeFlows/msalClientCertificate.js.map +0 -1
- package/dist-esm/src/msal/nodeFlows/msalClientSecret.js +0 -33
- package/dist-esm/src/msal/nodeFlows/msalClientSecret.js.map +0 -1
- package/dist-esm/src/msal/nodeFlows/msalDeviceCode.js +0 -35
- package/dist-esm/src/msal/nodeFlows/msalDeviceCode.js.map +0 -1
- package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js +0 -323
- package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js.map +0 -1
- package/dist-esm/src/msal/nodeFlows/msalOnBehalfOf.js +0 -58
- package/dist-esm/src/msal/nodeFlows/msalOnBehalfOf.js.map +0 -1
- package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js +0 -113
- package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js.map +0 -1
- package/dist-esm/src/msal/nodeFlows/msalUsernamePassword.js +0 -33
- package/dist-esm/src/msal/nodeFlows/msalUsernamePassword.js.map +0 -1
package/dist/index.js
CHANGED
@@ -6,18 +6,18 @@ var logger$m = require('@azure/logger');
|
|
6
6
|
var coreClient = require('@azure/core-client');
|
7
7
|
var coreUtil = require('@azure/core-util');
|
8
8
|
var coreRestPipeline = require('@azure/core-rest-pipeline');
|
9
|
-
var abortController = require('@azure/abort-controller');
|
10
9
|
var coreTracing = require('@azure/core-tracing');
|
11
10
|
var fs = require('fs');
|
12
11
|
var os = require('os');
|
13
12
|
var path = require('path');
|
13
|
+
var abortController = require('@azure/abort-controller');
|
14
14
|
var msalCommon = require('@azure/msal-node');
|
15
15
|
var open = require('open');
|
16
16
|
var promises = require('fs/promises');
|
17
17
|
var child_process = require('child_process');
|
18
18
|
var crypto = require('crypto');
|
19
|
-
var promises$1 = require('node:fs/promises');
|
20
19
|
var node_crypto = require('node:crypto');
|
20
|
+
var promises$1 = require('node:fs/promises');
|
21
21
|
|
22
22
|
function _interopNamespaceDefault(e) {
|
23
23
|
var n = Object.create(null);
|
@@ -40,11 +40,11 @@ var msalCommon__namespace = /*#__PURE__*/_interopNamespaceDefault(msalCommon);
|
|
40
40
|
var child_process__namespace = /*#__PURE__*/_interopNamespaceDefault(child_process);
|
41
41
|
|
42
42
|
// Copyright (c) Microsoft Corporation.
|
43
|
-
// Licensed under the MIT
|
43
|
+
// Licensed under the MIT License.
|
44
44
|
/**
|
45
45
|
* Current version of the `@azure/identity` package.
|
46
46
|
*/
|
47
|
-
const SDK_VERSION = `4.5.0-beta.
|
47
|
+
const SDK_VERSION = `4.5.0-beta.3`;
|
48
48
|
/**
|
49
49
|
* The default client ID for authentication
|
50
50
|
* @internal
|
@@ -107,7 +107,7 @@ const CACHE_NON_CAE_SUFFIX = "nocae";
|
|
107
107
|
const DEFAULT_TOKEN_CACHE_NAME = "msal.cache";
|
108
108
|
|
109
109
|
// Copyright (c) Microsoft Corporation.
|
110
|
-
// Licensed under the MIT
|
110
|
+
// Licensed under the MIT License.
|
111
111
|
/**
|
112
112
|
* The current persistence provider, undefined by default.
|
113
113
|
* @internal
|
@@ -190,7 +190,7 @@ const msalPlugins = {
|
|
190
190
|
};
|
191
191
|
|
192
192
|
// Copyright (c) Microsoft Corporation.
|
193
|
-
// Licensed under the MIT
|
193
|
+
// Licensed under the MIT License.
|
194
194
|
/**
|
195
195
|
* The AzureLogger used for all clients within the identity package
|
196
196
|
*/
|
@@ -273,7 +273,7 @@ function credentialLogger(title, log = logger$l) {
|
|
273
273
|
}
|
274
274
|
|
275
275
|
// Copyright (c) Microsoft Corporation.
|
276
|
-
// Licensed under the MIT
|
276
|
+
// Licensed under the MIT License.
|
277
277
|
function isErrorResponse(errorResponse) {
|
278
278
|
return (errorResponse &&
|
279
279
|
typeof errorResponse.error === "string" &&
|
@@ -289,8 +289,9 @@ const CredentialUnavailableErrorName = "CredentialUnavailableError";
|
|
289
289
|
* an error that should halt the chain, it's caught and the chain continues
|
290
290
|
*/
|
291
291
|
class CredentialUnavailableError extends Error {
|
292
|
-
constructor(message) {
|
293
|
-
|
292
|
+
constructor(message, options) {
|
293
|
+
// @ts-expect-error - TypeScript does not recognize this until we use ES2022 as the target; however, all our major runtimes do support the `cause` property
|
294
|
+
super(message, options);
|
294
295
|
this.name = CredentialUnavailableErrorName;
|
295
296
|
}
|
296
297
|
}
|
@@ -304,8 +305,7 @@ const AuthenticationErrorName = "AuthenticationError";
|
|
304
305
|
* the specific failure.
|
305
306
|
*/
|
306
307
|
class AuthenticationError extends Error {
|
307
|
-
|
308
|
-
constructor(statusCode, errorBody) {
|
308
|
+
constructor(statusCode, errorBody, options) {
|
309
309
|
let errorResponse = {
|
310
310
|
error: "unknown",
|
311
311
|
errorDescription: "An unknown error occurred and no additional details are available.",
|
@@ -323,8 +323,8 @@ class AuthenticationError extends Error {
|
|
323
323
|
catch (e) {
|
324
324
|
if (statusCode === 400) {
|
325
325
|
errorResponse = {
|
326
|
-
error: "
|
327
|
-
errorDescription:
|
326
|
+
error: "invalid_request",
|
327
|
+
errorDescription: `The service indicated that the request was invalid.\n\n${errorBody}`,
|
328
328
|
};
|
329
329
|
}
|
330
330
|
else {
|
@@ -341,7 +341,9 @@ class AuthenticationError extends Error {
|
|
341
341
|
errorDescription: "An unknown error occurred and no additional details are available.",
|
342
342
|
};
|
343
343
|
}
|
344
|
-
super(`${errorResponse.error} Status code: ${statusCode}\nMore details:\n${errorResponse.errorDescription}
|
344
|
+
super(`${errorResponse.error} Status code: ${statusCode}\nMore details:\n${errorResponse.errorDescription},`,
|
345
|
+
// @ts-expect-error - TypeScript does not recognize this until we use ES2022 as the target; however, all our major runtimes do support the `cause` property
|
346
|
+
options);
|
345
347
|
this.statusCode = statusCode;
|
346
348
|
this.errorResponse = errorResponse;
|
347
349
|
// Ensure that this type reports the correct name
|
@@ -384,7 +386,9 @@ class AuthenticationRequiredError extends Error {
|
|
384
386
|
* 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.
|
385
387
|
*/
|
386
388
|
options) {
|
387
|
-
super(options.message
|
389
|
+
super(options.message,
|
390
|
+
// @ts-expect-error - TypeScript does not recognize this until we use ES2022 as the target; however, all our major runtimes do support the `cause` property
|
391
|
+
options.cause ? { cause: options.cause } : undefined);
|
388
392
|
this.scopes = options.scopes;
|
389
393
|
this.getTokenOptions = options.getTokenOptions;
|
390
394
|
this.name = "AuthenticationRequiredError";
|
@@ -392,7 +396,7 @@ class AuthenticationRequiredError extends Error {
|
|
392
396
|
}
|
393
397
|
|
394
398
|
// Copyright (c) Microsoft Corporation.
|
395
|
-
// Licensed under the MIT
|
399
|
+
// Licensed under the MIT License.
|
396
400
|
function createConfigurationErrorMessage(tenantId) {
|
397
401
|
return `The current credential is not configured to acquire tokens for tenant ${tenantId}. To enable acquiring tokens for this tenant add it to the AdditionallyAllowedTenants on the credential options, or add "*" to AdditionallyAllowedTenants to allow acquiring tokens for any tenant.`;
|
398
402
|
}
|
@@ -426,7 +430,7 @@ function processMultiTenantRequest(tenantId, getTokenOptions, additionallyAllowe
|
|
426
430
|
}
|
427
431
|
|
428
432
|
// Copyright (c) Microsoft Corporation.
|
429
|
-
// Licensed under the MIT
|
433
|
+
// Licensed under the MIT License.
|
430
434
|
/**
|
431
435
|
* @internal
|
432
436
|
*/
|
@@ -467,7 +471,7 @@ function resolveAdditionallyAllowedTenantIds(additionallyAllowedTenants) {
|
|
467
471
|
}
|
468
472
|
|
469
473
|
// Copyright (c) Microsoft Corporation.
|
470
|
-
// Licensed under the MIT
|
474
|
+
// Licensed under the MIT License.
|
471
475
|
function getIdentityTokenEndpointSuffix(tenantId) {
|
472
476
|
if (tenantId === "adfs") {
|
473
477
|
return "oauth2/token";
|
@@ -478,7 +482,7 @@ function getIdentityTokenEndpointSuffix(tenantId) {
|
|
478
482
|
}
|
479
483
|
|
480
484
|
// Copyright (c) Microsoft Corporation.
|
481
|
-
// Licensed under the MIT
|
485
|
+
// Licensed under the MIT License.
|
482
486
|
/**
|
483
487
|
* Creates a span using the global tracer.
|
484
488
|
* @internal
|
@@ -490,14 +494,14 @@ const tracingClient = coreTracing.createTracingClient({
|
|
490
494
|
});
|
491
495
|
|
492
496
|
// Copyright (c) Microsoft Corporation.
|
493
|
-
// Licensed under the MIT
|
497
|
+
// Licensed under the MIT License.
|
494
498
|
const DefaultScopeSuffix = "/.default";
|
495
499
|
const imdsHost = "http://169.254.169.254";
|
496
500
|
const imdsEndpointPath = "/metadata/identity/oauth2/token";
|
497
501
|
const imdsApiVersion = "2018-02-01";
|
498
502
|
|
499
503
|
// Copyright (c) Microsoft Corporation.
|
500
|
-
// Licensed under the MIT
|
504
|
+
// Licensed under the MIT License.
|
501
505
|
/**
|
502
506
|
* Most MSIs send requests to the IMDS endpoint, or a similar endpoint.
|
503
507
|
* These are GET requests that require sending a `resource` parameter on the query.
|
@@ -546,9 +550,34 @@ function parseExpirationTimestamp(body) {
|
|
546
550
|
}
|
547
551
|
throw new Error(`Failed to parse token expiration from body. expires_in="${body.expires_in}", expires_on="${body.expires_on}"`);
|
548
552
|
}
|
553
|
+
/**
|
554
|
+
* Given a token response, return the expiration timestamp as the number of milliseconds from the Unix epoch.
|
555
|
+
* @param body - A parsed response body from the authentication endpoint.
|
556
|
+
*/
|
557
|
+
function parseRefreshTimestamp(body) {
|
558
|
+
if (body.refresh_on) {
|
559
|
+
if (typeof body.refresh_on === "number") {
|
560
|
+
return body.refresh_on * 1000;
|
561
|
+
}
|
562
|
+
if (typeof body.refresh_on === "string") {
|
563
|
+
const asNumber = +body.refresh_on;
|
564
|
+
if (!isNaN(asNumber)) {
|
565
|
+
return asNumber * 1000;
|
566
|
+
}
|
567
|
+
const asDate = Date.parse(body.refresh_on);
|
568
|
+
if (!isNaN(asDate)) {
|
569
|
+
return asDate;
|
570
|
+
}
|
571
|
+
}
|
572
|
+
throw new Error(`Failed to parse refresh_on from body. refresh_on="${body.refresh_on}"`);
|
573
|
+
}
|
574
|
+
else {
|
575
|
+
return undefined;
|
576
|
+
}
|
577
|
+
}
|
549
578
|
|
550
579
|
// Copyright (c) Microsoft Corporation.
|
551
|
-
// Licensed under the MIT
|
580
|
+
// Licensed under the MIT License.
|
552
581
|
const noCorrelationId = "noCorrelationId";
|
553
582
|
/**
|
554
583
|
* @internal
|
@@ -610,6 +639,7 @@ class IdentityClient extends coreClient.ServiceClient {
|
|
610
639
|
accessToken: {
|
611
640
|
token: parsedBody.access_token,
|
612
641
|
expiresOnTimestamp: parseExpirationTimestamp(parsedBody),
|
642
|
+
refreshAfterTimestamp: parseRefreshTimestamp(parsedBody),
|
613
643
|
},
|
614
644
|
refreshToken: parsedBody.refresh_token,
|
615
645
|
};
|
@@ -674,7 +704,7 @@ class IdentityClient extends coreClient.ServiceClient {
|
|
674
704
|
// Here is a custom layer that allows us to abort requests that go through MSAL,
|
675
705
|
// since MSAL doesn't allow us to pass options all the way through.
|
676
706
|
generateAbortSignal(correlationId) {
|
677
|
-
const controller = new
|
707
|
+
const controller = new AbortController();
|
678
708
|
const controllers = this.abortControllers.get(correlationId) || [];
|
679
709
|
controllers.push(controller);
|
680
710
|
this.abortControllers.set(correlationId, controllers);
|
@@ -682,7 +712,7 @@ class IdentityClient extends coreClient.ServiceClient {
|
|
682
712
|
controller.signal.onabort = (...params) => {
|
683
713
|
this.abortControllers.set(correlationId, undefined);
|
684
714
|
if (existingOnAbort) {
|
685
|
-
existingOnAbort(
|
715
|
+
existingOnAbort.apply(controller.signal, params);
|
686
716
|
}
|
687
717
|
};
|
688
718
|
return controller.signal;
|
@@ -785,7 +815,7 @@ class IdentityClient extends coreClient.ServiceClient {
|
|
785
815
|
}
|
786
816
|
|
787
817
|
// Copyright (c) Microsoft Corporation.
|
788
|
-
// Licensed under the MIT
|
818
|
+
// Licensed under the MIT License.
|
789
819
|
const CommonTenantId = "common";
|
790
820
|
const AzureAccountClientId = "aebc6443-996d-45c2-90f0-388ff96faa56"; // VSC: 'aebc6443-996d-45c2-90f0-388ff96faa56'
|
791
821
|
const logger$k = credentialLogger("VisualStudioCodeCredential");
|
@@ -966,7 +996,7 @@ class VisualStudioCodeCredential {
|
|
966
996
|
}
|
967
997
|
|
968
998
|
// Copyright (c) Microsoft Corporation.
|
969
|
-
// Licensed under the MIT
|
999
|
+
// Licensed under the MIT License.
|
970
1000
|
/**
|
971
1001
|
* The context passed to an Identity plugin. This contains objects that
|
972
1002
|
* plugins can use to set backend implementations.
|
@@ -1009,7 +1039,7 @@ function useIdentityPlugin(plugin) {
|
|
1009
1039
|
}
|
1010
1040
|
|
1011
1041
|
// Copyright (c) Microsoft Corporation.
|
1012
|
-
// Licensed under the MIT
|
1042
|
+
// Licensed under the MIT License.
|
1013
1043
|
/**
|
1014
1044
|
* @internal
|
1015
1045
|
*/
|
@@ -1042,6 +1072,19 @@ function ensureValidMsalToken(scopes, msalToken, getTokenOptions) {
|
|
1042
1072
|
throw error(`Response had no "accessToken" property.`);
|
1043
1073
|
}
|
1044
1074
|
}
|
1075
|
+
/**
|
1076
|
+
* Returns the authority host from either the options bag or the AZURE_AUTHORITY_HOST environment variable.
|
1077
|
+
*
|
1078
|
+
* Defaults to {@link DefaultAuthorityHost}.
|
1079
|
+
* @internal
|
1080
|
+
*/
|
1081
|
+
function getAuthorityHost(options) {
|
1082
|
+
let authorityHost = options === null || options === void 0 ? void 0 : options.authorityHost;
|
1083
|
+
if (!authorityHost && coreUtil.isNodeLike) {
|
1084
|
+
authorityHost = process.env.AZURE_AUTHORITY_HOST;
|
1085
|
+
}
|
1086
|
+
return authorityHost !== null && authorityHost !== void 0 ? authorityHost : DefaultAuthorityHost;
|
1087
|
+
}
|
1045
1088
|
/**
|
1046
1089
|
* Generates a valid authority by combining a host with a tenantId.
|
1047
1090
|
* @internal
|
@@ -1211,7 +1254,7 @@ function deserializeAuthenticationRecord(serializedRecord) {
|
|
1211
1254
|
}
|
1212
1255
|
|
1213
1256
|
// Copyright (c) Microsoft Corporation.
|
1214
|
-
// Licensed under the MIT
|
1257
|
+
// Licensed under the MIT License.
|
1215
1258
|
const msiName$1 = "ManagedIdentityCredential - IMDS";
|
1216
1259
|
const logger$i = credentialLogger(msiName$1);
|
1217
1260
|
/**
|
@@ -1348,7 +1391,7 @@ const imdsMsi = {
|
|
1348
1391
|
};
|
1349
1392
|
|
1350
1393
|
// Copyright (c) Microsoft Corporation.
|
1351
|
-
// Licensed under the MIT
|
1394
|
+
// Licensed under the MIT License.
|
1352
1395
|
// Matches the default retry configuration in expontentialRetryStrategy.ts
|
1353
1396
|
const DEFAULT_CLIENT_MAX_RETRY_INTERVAL = 1000 * 64;
|
1354
1397
|
/**
|
@@ -1367,14 +1410,10 @@ function imdsRetryPolicy(msiRetryConfig) {
|
|
1367
1410
|
if ((response === null || response === void 0 ? void 0 : response.status) !== 404) {
|
1368
1411
|
return { skipStrategy: true };
|
1369
1412
|
}
|
1370
|
-
|
1371
|
-
|
1372
|
-
|
1373
|
-
|
1374
|
-
// Allow the final value to have some "jitter" (within 50% of the delay size) so
|
1375
|
-
// that retries across multiple clients don't occur simultaneously.
|
1376
|
-
const retryAfterInMs = clampedExponentialDelay / 2 + coreUtil.getRandomIntegerInclusive(0, clampedExponentialDelay / 2);
|
1377
|
-
return { retryAfterInMs };
|
1413
|
+
return coreUtil.calculateRetryDelay(retryCount, {
|
1414
|
+
retryDelayInMs: msiRetryConfig.startDelayInMs,
|
1415
|
+
maxRetryDelayInMs: DEFAULT_CLIENT_MAX_RETRY_INTERVAL,
|
1416
|
+
});
|
1378
1417
|
},
|
1379
1418
|
},
|
1380
1419
|
], {
|
@@ -1383,7 +1422,7 @@ function imdsRetryPolicy(msiRetryConfig) {
|
|
1383
1422
|
}
|
1384
1423
|
|
1385
1424
|
// Copyright (c) Microsoft Corporation.
|
1386
|
-
// Licensed under the MIT
|
1425
|
+
// Licensed under the MIT License.
|
1387
1426
|
/**
|
1388
1427
|
* Helps specify a regional authority, or "AutoDiscoverRegion" to auto-detect the region.
|
1389
1428
|
*/
|
@@ -1523,7 +1562,11 @@ function calculateRegionalAuthority(regionalAuthority) {
|
|
1523
1562
|
}
|
1524
1563
|
|
1525
1564
|
// Copyright (c) Microsoft Corporation.
|
1526
|
-
// Licensed under the MIT
|
1565
|
+
// Licensed under the MIT License.
|
1566
|
+
/**
|
1567
|
+
* The default logger used if no logger was passed in by the credential.
|
1568
|
+
*/
|
1569
|
+
const msalLogger = credentialLogger("MsalClient");
|
1527
1570
|
/**
|
1528
1571
|
* A call to open(), but mockable
|
1529
1572
|
* @internal
|
@@ -1531,13 +1574,6 @@ function calculateRegionalAuthority(regionalAuthority) {
|
|
1531
1574
|
const interactiveBrowserMockable = {
|
1532
1575
|
open,
|
1533
1576
|
};
|
1534
|
-
|
1535
|
-
// Copyright (c) Microsoft Corporation.
|
1536
|
-
// Licensed under the MIT license.
|
1537
|
-
/**
|
1538
|
-
* The default logger used if no logger was passed in by the credential.
|
1539
|
-
*/
|
1540
|
-
const msalLogger = credentialLogger("MsalClient");
|
1541
1577
|
/**
|
1542
1578
|
* Generates the configuration for MSAL (Microsoft Authentication Library).
|
1543
1579
|
*
|
@@ -1547,10 +1583,10 @@ const msalLogger = credentialLogger("MsalClient");
|
|
1547
1583
|
* @returns The MSAL configuration object.
|
1548
1584
|
*/
|
1549
1585
|
function generateMsalConfiguration(clientId, tenantId, msalClientOptions = {}) {
|
1550
|
-
var _a, _b, _c
|
1586
|
+
var _a, _b, _c;
|
1551
1587
|
const resolvedTenant = resolveTenantId((_a = msalClientOptions.logger) !== null && _a !== void 0 ? _a : msalLogger, tenantId, clientId);
|
1552
1588
|
// TODO: move and reuse getIdentityClientAuthorityHost
|
1553
|
-
const authority = getAuthority(resolvedTenant, (
|
1589
|
+
const authority = getAuthority(resolvedTenant, getAuthorityHost(msalClientOptions));
|
1554
1590
|
const httpClient = new IdentityClient(Object.assign(Object.assign({}, msalClientOptions.tokenCredentialOptions), { authorityHost: authority, loggingOptions: msalClientOptions.loggingOptions }));
|
1555
1591
|
const msalConfig = {
|
1556
1592
|
auth: {
|
@@ -1561,9 +1597,9 @@ function generateMsalConfiguration(clientId, tenantId, msalClientOptions = {}) {
|
|
1561
1597
|
system: {
|
1562
1598
|
networkClient: httpClient,
|
1563
1599
|
loggerOptions: {
|
1564
|
-
loggerCallback: defaultLoggerCallback((
|
1600
|
+
loggerCallback: defaultLoggerCallback((_b = msalClientOptions.logger) !== null && _b !== void 0 ? _b : msalLogger),
|
1565
1601
|
logLevel: getMSALLogLevel(logger$m.getLogLevel()),
|
1566
|
-
piiLoggingEnabled: (
|
1602
|
+
piiLoggingEnabled: (_c = msalClientOptions.loggingOptions) === null || _c === void 0 ? void 0 : _c.enableUnsafeSupportLogging,
|
1567
1603
|
},
|
1568
1604
|
},
|
1569
1605
|
};
|
@@ -1668,7 +1704,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
1668
1704
|
*/
|
1669
1705
|
function calculateRequestAuthority(options) {
|
1670
1706
|
if (options === null || options === void 0 ? void 0 : options.tenantId) {
|
1671
|
-
return getAuthority(options.tenantId, createMsalClientOptions
|
1707
|
+
return getAuthority(options.tenantId, getAuthorityHost(createMsalClientOptions));
|
1672
1708
|
}
|
1673
1709
|
return state.msalConfig.auth.authority;
|
1674
1710
|
}
|
@@ -1683,7 +1719,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
1683
1719
|
* @returns A promise that resolves to an AccessToken object containing the access token and its expiration timestamp.
|
1684
1720
|
*/
|
1685
1721
|
async function withSilentAuthentication(msalApp, scopes, options, onAuthenticationRequired) {
|
1686
|
-
var _a;
|
1722
|
+
var _a, _b;
|
1687
1723
|
let response = null;
|
1688
1724
|
try {
|
1689
1725
|
response = await getTokenSilent(msalApp, scopes, options);
|
@@ -1716,9 +1752,11 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
1716
1752
|
return {
|
1717
1753
|
token: response.accessToken,
|
1718
1754
|
expiresOnTimestamp: response.expiresOn.getTime(),
|
1755
|
+
refreshAfterTimestamp: (_b = response.refreshOn) === null || _b === void 0 ? void 0 : _b.getTime(),
|
1719
1756
|
};
|
1720
1757
|
}
|
1721
1758
|
async function getTokenByClientSecret(scopes, clientSecret, options = {}) {
|
1759
|
+
var _a;
|
1722
1760
|
state.logger.getToken.info(`Attempting to acquire token using client secret`);
|
1723
1761
|
state.msalConfig.auth.clientSecret = clientSecret;
|
1724
1762
|
const msalApp = await getConfidentialApp(options);
|
@@ -1734,6 +1772,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
1734
1772
|
return {
|
1735
1773
|
token: response.accessToken,
|
1736
1774
|
expiresOnTimestamp: response.expiresOn.getTime(),
|
1775
|
+
refreshAfterTimestamp: (_a = response.refreshOn) === null || _a === void 0 ? void 0 : _a.getTime(),
|
1737
1776
|
};
|
1738
1777
|
}
|
1739
1778
|
catch (err) {
|
@@ -1741,6 +1780,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
1741
1780
|
}
|
1742
1781
|
}
|
1743
1782
|
async function getTokenByClientAssertion(scopes, clientAssertion, options = {}) {
|
1783
|
+
var _a;
|
1744
1784
|
state.logger.getToken.info(`Attempting to acquire token using client assertion`);
|
1745
1785
|
state.msalConfig.auth.clientAssertion = clientAssertion;
|
1746
1786
|
const msalApp = await getConfidentialApp(options);
|
@@ -1757,6 +1797,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
1757
1797
|
return {
|
1758
1798
|
token: response.accessToken,
|
1759
1799
|
expiresOnTimestamp: response.expiresOn.getTime(),
|
1800
|
+
refreshAfterTimestamp: (_a = response.refreshOn) === null || _a === void 0 ? void 0 : _a.getTime(),
|
1760
1801
|
};
|
1761
1802
|
}
|
1762
1803
|
catch (err) {
|
@@ -1764,6 +1805,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
1764
1805
|
}
|
1765
1806
|
}
|
1766
1807
|
async function getTokenByClientCertificate(scopes, certificate, options = {}) {
|
1808
|
+
var _a;
|
1767
1809
|
state.logger.getToken.info(`Attempting to acquire token using client certificate`);
|
1768
1810
|
state.msalConfig.auth.clientCertificate = certificate;
|
1769
1811
|
const msalApp = await getConfidentialApp(options);
|
@@ -1779,6 +1821,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
1779
1821
|
return {
|
1780
1822
|
token: response.accessToken,
|
1781
1823
|
expiresOnTimestamp: response.expiresOn.getTime(),
|
1824
|
+
refreshAfterTimestamp: (_a = response.refreshOn) === null || _a === void 0 ? void 0 : _a.getTime(),
|
1782
1825
|
};
|
1783
1826
|
}
|
1784
1827
|
catch (err) {
|
@@ -1849,6 +1892,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
1849
1892
|
});
|
1850
1893
|
}
|
1851
1894
|
async function getTokenOnBehalfOf(scopes, userAssertionToken, clientCredentials, options = {}) {
|
1895
|
+
var _a;
|
1852
1896
|
msalLogger.getToken.info(`Attempting to acquire token on behalf of another user`);
|
1853
1897
|
if (typeof clientCredentials === "string") {
|
1854
1898
|
// Client secret
|
@@ -1878,6 +1922,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
1878
1922
|
return {
|
1879
1923
|
token: response.accessToken,
|
1880
1924
|
expiresOnTimestamp: response.expiresOn.getTime(),
|
1925
|
+
refreshAfterTimestamp: (_a = response.refreshOn) === null || _a === void 0 ? void 0 : _a.getTime(),
|
1881
1926
|
};
|
1882
1927
|
}
|
1883
1928
|
catch (err) {
|
@@ -1966,7 +2011,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
1966
2011
|
}
|
1967
2012
|
|
1968
2013
|
// Copyright (c) Microsoft Corporation.
|
1969
|
-
// Licensed under the MIT
|
2014
|
+
// Licensed under the MIT License.
|
1970
2015
|
const logger$h = credentialLogger("ClientAssertionCredential");
|
1971
2016
|
/**
|
1972
2017
|
* Authenticates a service principal with a JWT assertion.
|
@@ -1983,8 +2028,14 @@ class ClientAssertionCredential {
|
|
1983
2028
|
* @param options - Options for configuring the client which makes the authentication request.
|
1984
2029
|
*/
|
1985
2030
|
constructor(tenantId, clientId, getAssertion, options = {}) {
|
1986
|
-
if (!tenantId
|
1987
|
-
throw new
|
2031
|
+
if (!tenantId) {
|
2032
|
+
throw new CredentialUnavailableError("ClientAssertionCredential: tenantId is a required parameter.");
|
2033
|
+
}
|
2034
|
+
if (!clientId) {
|
2035
|
+
throw new CredentialUnavailableError("ClientAssertionCredential: clientId is a required parameter.");
|
2036
|
+
}
|
2037
|
+
if (!getAssertion) {
|
2038
|
+
throw new CredentialUnavailableError("ClientAssertionCredential: clientAssertion is a required parameter.");
|
1988
2039
|
}
|
1989
2040
|
this.tenantId = tenantId;
|
1990
2041
|
this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
|
@@ -2010,7 +2061,7 @@ class ClientAssertionCredential {
|
|
2010
2061
|
}
|
2011
2062
|
|
2012
2063
|
// Copyright (c) Microsoft Corporation.
|
2013
|
-
// Licensed under the MIT
|
2064
|
+
// Licensed under the MIT License.
|
2014
2065
|
const credentialName$4 = "WorkloadIdentityCredential";
|
2015
2066
|
/**
|
2016
2067
|
* Contains the list of all supported environment variable names so that an
|
@@ -2059,10 +2110,20 @@ class WorkloadIdentityCredential {
|
|
2059
2110
|
if (tenantId) {
|
2060
2111
|
checkTenantId(logger$g, tenantId);
|
2061
2112
|
}
|
2062
|
-
if (clientId
|
2063
|
-
|
2064
|
-
|
2113
|
+
if (!clientId) {
|
2114
|
+
throw new CredentialUnavailableError(`${credentialName$4}: is unavailable. clientId is a required parameter. In DefaultAzureCredential and ManagedIdentityCredential, this can be provided as an environment variable - "AZURE_CLIENT_ID".
|
2115
|
+
See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`);
|
2065
2116
|
}
|
2117
|
+
if (!tenantId) {
|
2118
|
+
throw new CredentialUnavailableError(`${credentialName$4}: is unavailable. tenantId is a required parameter. In DefaultAzureCredential and ManagedIdentityCredential, this can be provided as an environment variable - "AZURE_TENANT_ID".
|
2119
|
+
See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`);
|
2120
|
+
}
|
2121
|
+
if (!this.federatedTokenFilePath) {
|
2122
|
+
throw new CredentialUnavailableError(`${credentialName$4}: is unavailable. federatedTokenFilePath is a required parameter. In DefaultAzureCredential and ManagedIdentityCredential, this can be provided as an environment variable - "AZURE_FEDERATED_TOKEN_FILE".
|
2123
|
+
See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`);
|
2124
|
+
}
|
2125
|
+
logger$g.info(`Invoking ClientAssertionCredential with tenant ID: ${tenantId}, clientId: ${workloadIdentityCredentialOptions.clientId} and federated token path: [REDACTED]`);
|
2126
|
+
this.client = new ClientAssertionCredential(tenantId, clientId, this.readFileContents.bind(this), options);
|
2066
2127
|
}
|
2067
2128
|
/**
|
2068
2129
|
* Authenticates with Microsoft Entra ID and returns an access token if successful.
|
@@ -2078,7 +2139,7 @@ class WorkloadIdentityCredential {
|
|
2078
2139
|
In DefaultAzureCredential and ManagedIdentityCredential, these can be provided as environment variables -
|
2079
2140
|
"AZURE_TENANT_ID",
|
2080
2141
|
"AZURE_CLIENT_ID",
|
2081
|
-
"AZURE_FEDERATED_TOKEN_FILE". See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot
|
2142
|
+
"AZURE_FEDERATED_TOKEN_FILE". See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot`;
|
2082
2143
|
logger$g.info(errorMessage);
|
2083
2144
|
throw new CredentialUnavailableError(errorMessage);
|
2084
2145
|
}
|
@@ -2109,7 +2170,7 @@ class WorkloadIdentityCredential {
|
|
2109
2170
|
}
|
2110
2171
|
|
2111
2172
|
// Copyright (c) Microsoft Corporation.
|
2112
|
-
// Licensed under the MIT
|
2173
|
+
// Licensed under the MIT License.
|
2113
2174
|
const msiName = "ManagedIdentityCredential - Token Exchange";
|
2114
2175
|
const logger$f = credentialLogger(msiName);
|
2115
2176
|
/**
|
@@ -2136,7 +2197,7 @@ const tokenExchangeMsi = {
|
|
2136
2197
|
};
|
2137
2198
|
|
2138
2199
|
// Copyright (c) Microsoft Corporation.
|
2139
|
-
// Licensed under the MIT
|
2200
|
+
// Licensed under the MIT License.
|
2140
2201
|
const logger$e = credentialLogger("ManagedIdentityCredential(MSAL)");
|
2141
2202
|
class MsalMsiProvider {
|
2142
2203
|
constructor(clientIdOrOptions, options = {}) {
|
@@ -2156,9 +2217,11 @@ class MsalMsiProvider {
|
|
2156
2217
|
_options = clientIdOrOptions !== null && clientIdOrOptions !== void 0 ? clientIdOrOptions : {};
|
2157
2218
|
}
|
2158
2219
|
this.resourceId = _options === null || _options === void 0 ? void 0 : _options.resourceId;
|
2220
|
+
this.objectId = _options === null || _options === void 0 ? void 0 : _options.objectId;
|
2159
2221
|
// For JavaScript users.
|
2160
|
-
|
2161
|
-
|
2222
|
+
const providedIds = [this.clientId, this.resourceId, this.objectId].filter(Boolean);
|
2223
|
+
if (providedIds.length > 1) {
|
2224
|
+
throw new Error(`ManagedIdentityCredential: only one of 'clientId', 'resourceId', or 'objectId' can be provided. Received values: ${JSON.stringify({ clientId: this.clientId, resourceId: this.resourceId, objectId: this.objectId })}`);
|
2162
2225
|
}
|
2163
2226
|
// ManagedIdentity uses http for local requests
|
2164
2227
|
_options.allowInsecureConnection = true;
|
@@ -2170,6 +2233,7 @@ class MsalMsiProvider {
|
|
2170
2233
|
managedIdentityIdParams: {
|
2171
2234
|
userAssignedClientId: this.clientId,
|
2172
2235
|
userAssignedResourceId: this.resourceId,
|
2236
|
+
userAssignedObjectId: this.objectId,
|
2173
2237
|
},
|
2174
2238
|
system: {
|
2175
2239
|
// todo: proxyUrl?
|
@@ -2185,6 +2249,17 @@ class MsalMsiProvider {
|
|
2185
2249
|
this.isAvailableIdentityClient = new IdentityClient(Object.assign(Object.assign({}, _options), { retryOptions: {
|
2186
2250
|
maxRetries: 0,
|
2187
2251
|
} }));
|
2252
|
+
// CloudShell MSI will ignore any user-assigned identity passed as parameters. To avoid confusion, we prevent this from happening as early as possible.
|
2253
|
+
if (this.managedIdentityApp.getManagedIdentitySource() === "CloudShell") {
|
2254
|
+
if (this.clientId || this.resourceId || this.objectId) {
|
2255
|
+
logger$e.warning(`CloudShell MSI detected with user-provided IDs - throwing. Received values: ${JSON.stringify({
|
2256
|
+
clientId: this.clientId,
|
2257
|
+
resourceId: this.resourceId,
|
2258
|
+
objectId: this.objectId,
|
2259
|
+
})}.`);
|
2260
|
+
throw new CredentialUnavailableError("ManagedIdentityCredential: Specifying a user-assigned managed identity is not supported for CloudShell at runtime. When using Managed Identity in CloudShell, omit the clientId, resourceId, and objectId parameters.");
|
2261
|
+
}
|
2262
|
+
}
|
2188
2263
|
}
|
2189
2264
|
/**
|
2190
2265
|
* Authenticates with Microsoft Entra ID and returns an access token if successful.
|
@@ -2202,6 +2277,7 @@ class MsalMsiProvider {
|
|
2202
2277
|
throw new CredentialUnavailableError(`ManagedIdentityCredential: Multiple scopes are not supported. Scopes: ${JSON.stringify(scopes)}`);
|
2203
2278
|
}
|
2204
2279
|
return tracingClient.withSpan("ManagedIdentityCredential.getToken", options, async () => {
|
2280
|
+
var _a;
|
2205
2281
|
try {
|
2206
2282
|
const isTokenExchangeMsi = await tokenExchangeMsi.isAvailable({
|
2207
2283
|
scopes,
|
@@ -2217,6 +2293,7 @@ class MsalMsiProvider {
|
|
2217
2293
|
// We will continue to implement these features in the Identity library.
|
2218
2294
|
const identitySource = this.managedIdentityApp.getManagedIdentitySource();
|
2219
2295
|
const isImdsMsi = identitySource === "DefaultToImds" || identitySource === "Imds"; // Neither actually checks that IMDS endpoint is available, just that it's the source the MSAL _would_ try to use.
|
2296
|
+
logger$e.getToken.info(`MSAL Identity source: ${identitySource}`);
|
2220
2297
|
if (isTokenExchangeMsi) {
|
2221
2298
|
// In the AKS scenario we will use the existing tokenExchangeMsi indefinitely.
|
2222
2299
|
logger$e.getToken.info("Using the token exchange managed identity.");
|
@@ -2228,7 +2305,7 @@ class MsalMsiProvider {
|
|
2228
2305
|
resourceId: this.resourceId,
|
2229
2306
|
});
|
2230
2307
|
if (result === null) {
|
2231
|
-
throw new CredentialUnavailableError("
|
2308
|
+
throw new CredentialUnavailableError("Attempted to use the token exchange managed identity, but received a null response.");
|
2232
2309
|
}
|
2233
2310
|
return result;
|
2234
2311
|
}
|
@@ -2244,7 +2321,7 @@ class MsalMsiProvider {
|
|
2244
2321
|
resourceId: this.resourceId,
|
2245
2322
|
});
|
2246
2323
|
if (!isAvailable) {
|
2247
|
-
throw new CredentialUnavailableError(`
|
2324
|
+
throw new CredentialUnavailableError(`Attempted to use the IMDS endpoint, but it is not available.`);
|
2248
2325
|
}
|
2249
2326
|
}
|
2250
2327
|
// If we got this far, it means:
|
@@ -2260,6 +2337,7 @@ class MsalMsiProvider {
|
|
2260
2337
|
return {
|
2261
2338
|
expiresOnTimestamp: token.expiresOn.getTime(),
|
2262
2339
|
token: token.accessToken,
|
2340
|
+
refreshAfterTimestamp: (_a = token.refreshOn) === null || _a === void 0 ? void 0 : _a.getTime(),
|
2263
2341
|
};
|
2264
2342
|
}
|
2265
2343
|
catch (err) {
|
@@ -2270,9 +2348,9 @@ class MsalMsiProvider {
|
|
2270
2348
|
throw err;
|
2271
2349
|
}
|
2272
2350
|
if (isNetworkError(err)) {
|
2273
|
-
throw new CredentialUnavailableError(`ManagedIdentityCredential: Network unreachable. Message: ${err.message}
|
2351
|
+
throw new CredentialUnavailableError(`ManagedIdentityCredential: Network unreachable. Message: ${err.message}`, { cause: err });
|
2274
2352
|
}
|
2275
|
-
throw new CredentialUnavailableError(`ManagedIdentityCredential: Authentication failed. Message ${err.message}
|
2353
|
+
throw new CredentialUnavailableError(`ManagedIdentityCredential: Authentication failed. Message ${err.message}`, { cause: err });
|
2276
2354
|
}
|
2277
2355
|
});
|
2278
2356
|
}
|
@@ -2289,7 +2367,7 @@ class MsalMsiProvider {
|
|
2289
2367
|
});
|
2290
2368
|
};
|
2291
2369
|
if (!msalToken) {
|
2292
|
-
throw createError("No response");
|
2370
|
+
throw createError("No response.");
|
2293
2371
|
}
|
2294
2372
|
if (!msalToken.expiresOn) {
|
2295
2373
|
throw createError(`Response had no "expiresOn" property.`);
|
@@ -2319,7 +2397,7 @@ function isNetworkError(err) {
|
|
2319
2397
|
}
|
2320
2398
|
|
2321
2399
|
// Copyright (c) Microsoft Corporation.
|
2322
|
-
// Licensed under the MIT
|
2400
|
+
// Licensed under the MIT License.
|
2323
2401
|
/**
|
2324
2402
|
* Attempts authentication using a managed identity available at the deployment environment.
|
2325
2403
|
* This authentication type works in Azure VMs, App Service instances, Azure Functions applications,
|
@@ -2355,7 +2433,7 @@ class ManagedIdentityCredential {
|
|
2355
2433
|
}
|
2356
2434
|
|
2357
2435
|
// Copyright (c) Microsoft Corporation.
|
2358
|
-
// Licensed under the MIT
|
2436
|
+
// Licensed under the MIT License.
|
2359
2437
|
/**
|
2360
2438
|
* Ensures the scopes value is an array.
|
2361
2439
|
* @internal
|
@@ -2383,7 +2461,7 @@ function getScopeResource(scope) {
|
|
2383
2461
|
}
|
2384
2462
|
|
2385
2463
|
// Copyright (c) Microsoft Corporation.
|
2386
|
-
// Licensed under the MIT
|
2464
|
+
// Licensed under the MIT License.
|
2387
2465
|
/**
|
2388
2466
|
* Mockable reference to the CLI credential cliCredentialFunctions
|
2389
2467
|
* @internal
|
@@ -2550,7 +2628,7 @@ class AzureCliCredential {
|
|
2550
2628
|
}
|
2551
2629
|
|
2552
2630
|
// Copyright (c) Microsoft Corporation.
|
2553
|
-
// Licensed under the MIT
|
2631
|
+
// Licensed under the MIT License.
|
2554
2632
|
/**
|
2555
2633
|
* Mockable reference to the Developer CLI credential cliCredentialFunctions
|
2556
2634
|
* @internal
|
@@ -2714,7 +2792,7 @@ class AzureDeveloperCliCredential {
|
|
2714
2792
|
}
|
2715
2793
|
|
2716
2794
|
// Copyright (c) Microsoft Corporation.
|
2717
|
-
// Licensed under the MIT
|
2795
|
+
// Licensed under the MIT License.
|
2718
2796
|
/**
|
2719
2797
|
* Easy to mock childProcess utils.
|
2720
2798
|
* @internal
|
@@ -2745,7 +2823,7 @@ const processUtils = {
|
|
2745
2823
|
};
|
2746
2824
|
|
2747
2825
|
// Copyright (c) Microsoft Corporation.
|
2748
|
-
// Licensed under the MIT
|
2826
|
+
// Licensed under the MIT License.
|
2749
2827
|
const logger$b = credentialLogger("AzurePowerShellCredential");
|
2750
2828
|
const isWindows = process.platform === "win32";
|
2751
2829
|
/**
|
@@ -2848,33 +2926,45 @@ class AzurePowerShellCredential {
|
|
2848
2926
|
commandStack.shift();
|
2849
2927
|
continue;
|
2850
2928
|
}
|
2851
|
-
let tenantSection = "";
|
2852
|
-
if (tenantId) {
|
2853
|
-
tenantSection = `-TenantId "${tenantId}"`;
|
2854
|
-
}
|
2855
2929
|
const results = await runCommands([
|
2856
2930
|
[
|
2857
2931
|
powerShellCommand,
|
2858
2932
|
"-NoProfile",
|
2859
2933
|
"-NonInteractive",
|
2860
2934
|
"-Command",
|
2861
|
-
|
2862
|
-
|
2863
|
-
|
2864
|
-
|
2865
|
-
|
2866
|
-
|
2867
|
-
|
2868
|
-
|
2935
|
+
`
|
2936
|
+
$tenantId = "${tenantId !== null && tenantId !== void 0 ? tenantId : ""}"
|
2937
|
+
$m = Import-Module Az.Accounts -MinimumVersion 2.2.0 -PassThru
|
2938
|
+
$useSecureString = $m.Version -ge [version]'2.17.0'
|
2939
|
+
|
2940
|
+
$params = @{
|
2941
|
+
ResourceUrl = "${resource}"
|
2942
|
+
}
|
2943
|
+
|
2944
|
+
if ($tenantId.Length -gt 0) {
|
2945
|
+
$params["TenantId"] = $tenantId
|
2946
|
+
}
|
2947
|
+
|
2948
|
+
if ($useSecureString) {
|
2949
|
+
$params["AsSecureString"] = $true
|
2950
|
+
}
|
2951
|
+
|
2952
|
+
$token = Get-AzAccessToken @params
|
2953
|
+
|
2954
|
+
$result = New-Object -TypeName PSObject
|
2955
|
+
$result | Add-Member -MemberType NoteProperty -Name ExpiresOn -Value $token.ExpiresOn
|
2956
|
+
if ($useSecureString) {
|
2957
|
+
$result | Add-Member -MemberType NoteProperty -Name Token -Value (ConvertFrom-SecureString -AsPlainText $token.Token)
|
2958
|
+
} else {
|
2959
|
+
$result | Add-Member -MemberType NoteProperty -Name Token -Value $token.Token
|
2960
|
+
}
|
2961
|
+
|
2962
|
+
Write-Output (ConvertTo-Json $result)
|
2963
|
+
`,
|
2869
2964
|
],
|
2870
2965
|
]);
|
2871
|
-
const result = results[
|
2872
|
-
|
2873
|
-
return JSON.parse(result);
|
2874
|
-
}
|
2875
|
-
catch (e) {
|
2876
|
-
throw new Error(`Unable to parse the output of PowerShell. Received output: ${result}`);
|
2877
|
-
}
|
2966
|
+
const result = results[0];
|
2967
|
+
return parseJsonToken(result);
|
2878
2968
|
}
|
2879
2969
|
throw new Error(`Unable to execute PowerShell. Ensure that it is installed in your system`);
|
2880
2970
|
}
|
@@ -2921,9 +3011,41 @@ class AzurePowerShellCredential {
|
|
2921
3011
|
});
|
2922
3012
|
}
|
2923
3013
|
}
|
3014
|
+
/**
|
3015
|
+
*
|
3016
|
+
* @internal
|
3017
|
+
*/
|
3018
|
+
async function parseJsonToken(result) {
|
3019
|
+
const jsonRegex = /{[^{}]*}/g;
|
3020
|
+
const matches = result.match(jsonRegex);
|
3021
|
+
let resultWithoutToken = result;
|
3022
|
+
if (matches) {
|
3023
|
+
try {
|
3024
|
+
for (const item of matches) {
|
3025
|
+
try {
|
3026
|
+
const jsonContent = JSON.parse(item);
|
3027
|
+
if (jsonContent === null || jsonContent === void 0 ? void 0 : jsonContent.Token) {
|
3028
|
+
resultWithoutToken = resultWithoutToken.replace(item, "");
|
3029
|
+
if (resultWithoutToken) {
|
3030
|
+
logger$b.getToken.warning(resultWithoutToken);
|
3031
|
+
}
|
3032
|
+
return jsonContent;
|
3033
|
+
}
|
3034
|
+
}
|
3035
|
+
catch (e) {
|
3036
|
+
continue;
|
3037
|
+
}
|
3038
|
+
}
|
3039
|
+
}
|
3040
|
+
catch (e) {
|
3041
|
+
throw new Error(`Unable to parse the output of PowerShell. Received output: ${result}`);
|
3042
|
+
}
|
3043
|
+
}
|
3044
|
+
throw new Error(`No access token found in the output. Received output: ${result}`);
|
3045
|
+
}
|
2924
3046
|
|
2925
3047
|
// Copyright (c) Microsoft Corporation.
|
2926
|
-
// Licensed under the MIT
|
3048
|
+
// Licensed under the MIT License.
|
2927
3049
|
/**
|
2928
3050
|
* @internal
|
2929
3051
|
*/
|
@@ -3002,7 +3124,7 @@ class ChainedTokenCredential {
|
|
3002
3124
|
}
|
3003
3125
|
|
3004
3126
|
// Copyright (c) Microsoft Corporation.
|
3005
|
-
// Licensed under the MIT
|
3127
|
+
// Licensed under the MIT License.
|
3006
3128
|
const credentialName$3 = "ClientCertificateCredential";
|
3007
3129
|
const logger$9 = credentialLogger(credentialName$3);
|
3008
3130
|
/**
|
@@ -3053,7 +3175,8 @@ class ClientCertificateCredential {
|
|
3053
3175
|
});
|
3054
3176
|
}
|
3055
3177
|
async buildClientCertificate() {
|
3056
|
-
|
3178
|
+
var _a;
|
3179
|
+
const parts = await parseCertificate(this.certificateConfiguration, (_a = this.sendCertificateChain) !== null && _a !== void 0 ? _a : false);
|
3057
3180
|
let privateKey;
|
3058
3181
|
if (this.certificateConfiguration.certificatePassword !== undefined) {
|
3059
3182
|
privateKey = crypto.createPrivateKey({
|
@@ -3076,38 +3199,45 @@ class ClientCertificateCredential {
|
|
3076
3199
|
x5c: parts.x5c,
|
3077
3200
|
};
|
3078
3201
|
}
|
3079
|
-
|
3080
|
-
|
3081
|
-
|
3082
|
-
|
3083
|
-
|
3084
|
-
|
3085
|
-
|
3086
|
-
|
3087
|
-
|
3088
|
-
|
3089
|
-
|
3090
|
-
|
3091
|
-
|
3092
|
-
|
3093
|
-
|
3094
|
-
|
3095
|
-
|
3202
|
+
}
|
3203
|
+
/**
|
3204
|
+
* Parses a certificate into its relevant parts
|
3205
|
+
*
|
3206
|
+
* @param certificateConfiguration - The certificate contents or path to the certificate
|
3207
|
+
* @param sendCertificateChain - true if the entire certificate chain should be sent for SNI, false otherwise
|
3208
|
+
* @returns The parsed certificate parts and the certificate contents
|
3209
|
+
*/
|
3210
|
+
async function parseCertificate(certificateConfiguration, sendCertificateChain) {
|
3211
|
+
const certificate = certificateConfiguration.certificate;
|
3212
|
+
const certificatePath = certificateConfiguration.certificatePath;
|
3213
|
+
const certificateContents = certificate || (await promises.readFile(certificatePath, "utf8"));
|
3214
|
+
const x5c = sendCertificateChain ? certificateContents : undefined;
|
3215
|
+
const certificatePattern = /(-+BEGIN CERTIFICATE-+)(\n\r?|\r\n?)([A-Za-z0-9+/\n\r]+=*)(\n\r?|\r\n?)(-+END CERTIFICATE-+)/g;
|
3216
|
+
const publicKeys = [];
|
3217
|
+
// Match all possible certificates, in the order they are in the file. These will form the chain that is used for x5c
|
3218
|
+
let match;
|
3219
|
+
do {
|
3220
|
+
match = certificatePattern.exec(certificateContents);
|
3221
|
+
if (match) {
|
3222
|
+
publicKeys.push(match[3]);
|
3096
3223
|
}
|
3097
|
-
|
3098
|
-
|
3099
|
-
|
3100
|
-
|
3101
|
-
|
3102
|
-
|
3103
|
-
|
3104
|
-
|
3105
|
-
|
3106
|
-
|
3224
|
+
} while (match);
|
3225
|
+
if (publicKeys.length === 0) {
|
3226
|
+
throw new Error("The file at the specified path does not contain a PEM-encoded certificate.");
|
3227
|
+
}
|
3228
|
+
const thumbprint = crypto.createHash("sha1")
|
3229
|
+
.update(Buffer.from(publicKeys[0], "base64"))
|
3230
|
+
.digest("hex")
|
3231
|
+
.toUpperCase();
|
3232
|
+
return {
|
3233
|
+
certificateContents,
|
3234
|
+
thumbprint,
|
3235
|
+
x5c,
|
3236
|
+
};
|
3107
3237
|
}
|
3108
3238
|
|
3109
3239
|
// Copyright (c) Microsoft Corporation.
|
3110
|
-
// Licensed under the MIT
|
3240
|
+
// Licensed under the MIT License.
|
3111
3241
|
const logger$8 = credentialLogger("ClientSecretCredential");
|
3112
3242
|
/**
|
3113
3243
|
* Enables authentication to Microsoft Entra ID using a client secret
|
@@ -3129,8 +3259,14 @@ class ClientSecretCredential {
|
|
3129
3259
|
* @param options - Options for configuring the client which makes the authentication request.
|
3130
3260
|
*/
|
3131
3261
|
constructor(tenantId, clientId, clientSecret, options = {}) {
|
3132
|
-
if (!tenantId
|
3133
|
-
throw new
|
3262
|
+
if (!tenantId) {
|
3263
|
+
throw new CredentialUnavailableError("ClientSecretCredential: tenantId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.");
|
3264
|
+
}
|
3265
|
+
if (!clientId) {
|
3266
|
+
throw new CredentialUnavailableError("ClientSecretCredential: clientId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.");
|
3267
|
+
}
|
3268
|
+
if (!clientSecret) {
|
3269
|
+
throw new CredentialUnavailableError("ClientSecretCredential: clientSecret is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.");
|
3134
3270
|
}
|
3135
3271
|
this.clientSecret = clientSecret;
|
3136
3272
|
this.tenantId = tenantId;
|
@@ -3155,7 +3291,7 @@ class ClientSecretCredential {
|
|
3155
3291
|
}
|
3156
3292
|
|
3157
3293
|
// Copyright (c) Microsoft Corporation.
|
3158
|
-
// Licensed under the MIT
|
3294
|
+
// Licensed under the MIT License.
|
3159
3295
|
const logger$7 = credentialLogger("UsernamePasswordCredential");
|
3160
3296
|
/**
|
3161
3297
|
* Enables authentication to Microsoft Entra ID with a user's
|
@@ -3176,8 +3312,17 @@ class UsernamePasswordCredential {
|
|
3176
3312
|
* @param options - Options for configuring the client which makes the authentication request.
|
3177
3313
|
*/
|
3178
3314
|
constructor(tenantId, clientId, username, password, options = {}) {
|
3179
|
-
if (!tenantId
|
3180
|
-
throw new
|
3315
|
+
if (!tenantId) {
|
3316
|
+
throw new CredentialUnavailableError("UsernamePasswordCredential: tenantId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.");
|
3317
|
+
}
|
3318
|
+
if (!clientId) {
|
3319
|
+
throw new CredentialUnavailableError("UsernamePasswordCredential: clientId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.");
|
3320
|
+
}
|
3321
|
+
if (!username) {
|
3322
|
+
throw new CredentialUnavailableError("UsernamePasswordCredential: username is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.");
|
3323
|
+
}
|
3324
|
+
if (!password) {
|
3325
|
+
throw new CredentialUnavailableError("UsernamePasswordCredential: password is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.");
|
3181
3326
|
}
|
3182
3327
|
this.tenantId = tenantId;
|
3183
3328
|
this.additionallyAllowedTenantIds = resolveAdditionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
|
@@ -3207,7 +3352,7 @@ class UsernamePasswordCredential {
|
|
3207
3352
|
}
|
3208
3353
|
|
3209
3354
|
// Copyright (c) Microsoft Corporation.
|
3210
|
-
// Licensed under the MIT
|
3355
|
+
// Licensed under the MIT License.
|
3211
3356
|
/**
|
3212
3357
|
* Contains the list of all supported environment variable names so that an
|
3213
3358
|
* appropriate error message can be generated when no credentials can be
|
@@ -3224,6 +3369,7 @@ const AllSupportedEnvironmentVariables = [
|
|
3224
3369
|
"AZURE_USERNAME",
|
3225
3370
|
"AZURE_PASSWORD",
|
3226
3371
|
"AZURE_ADDITIONALLY_ALLOWED_TENANTS",
|
3372
|
+
"AZURE_CLIENT_SEND_CERTIFICATE_CHAIN",
|
3227
3373
|
];
|
3228
3374
|
function getAdditionallyAllowedTenants() {
|
3229
3375
|
var _a;
|
@@ -3232,6 +3378,13 @@ function getAdditionallyAllowedTenants() {
|
|
3232
3378
|
}
|
3233
3379
|
const credentialName$2 = "EnvironmentCredential";
|
3234
3380
|
const logger$6 = credentialLogger(credentialName$2);
|
3381
|
+
function getSendCertificateChain() {
|
3382
|
+
var _a;
|
3383
|
+
const sendCertificateChain = ((_a = process.env.AZURE_CLIENT_SEND_CERTIFICATE_CHAIN) !== null && _a !== void 0 ? _a : "").toLowerCase();
|
3384
|
+
const result = sendCertificateChain === "true" || sendCertificateChain === "1";
|
3385
|
+
logger$6.verbose(`AZURE_CLIENT_SEND_CERTIFICATE_CHAIN: ${process.env.AZURE_CLIENT_SEND_CERTIFICATE_CHAIN}; sendCertificateChain: ${result}`);
|
3386
|
+
return result;
|
3387
|
+
}
|
3235
3388
|
/**
|
3236
3389
|
* Enables authentication to Microsoft Entra ID using a client secret or certificate, or as a user
|
3237
3390
|
* with a username and password.
|
@@ -3251,6 +3404,7 @@ class EnvironmentCredential {
|
|
3251
3404
|
* - `AZURE_CLIENT_SECRET`: A client secret that was generated for the App Registration.
|
3252
3405
|
* - `AZURE_CLIENT_CERTIFICATE_PATH`: The path to a PEM certificate to use during the authentication, instead of the client secret.
|
3253
3406
|
* - `AZURE_CLIENT_CERTIFICATE_PASSWORD`: (optional) password for the certificate file.
|
3407
|
+
* - `AZURE_CLIENT_SEND_CERTIFICATE_CHAIN`: (optional) indicates that the certificate chain should be set in x5c header to support subject name / issuer based authentication.
|
3254
3408
|
*
|
3255
3409
|
* Alternatively, users can provide environment variables for username and password authentication:
|
3256
3410
|
* - `AZURE_USERNAME`: Username to authenticate with.
|
@@ -3268,7 +3422,8 @@ class EnvironmentCredential {
|
|
3268
3422
|
logger$6.info(`Found the following environment variables: ${assigned}`);
|
3269
3423
|
const tenantId = process.env.AZURE_TENANT_ID, clientId = process.env.AZURE_CLIENT_ID, clientSecret = process.env.AZURE_CLIENT_SECRET;
|
3270
3424
|
const additionallyAllowedTenantIds = getAdditionallyAllowedTenants();
|
3271
|
-
const
|
3425
|
+
const sendCertificateChain = getSendCertificateChain();
|
3426
|
+
const newOptions = Object.assign(Object.assign({}, options), { additionallyAllowedTenantIds, sendCertificateChain });
|
3272
3427
|
if (tenantId) {
|
3273
3428
|
checkTenantId(logger$6, tenantId);
|
3274
3429
|
}
|
@@ -3320,7 +3475,7 @@ class EnvironmentCredential {
|
|
3320
3475
|
}
|
3321
3476
|
|
3322
3477
|
// Copyright (c) Microsoft Corporation.
|
3323
|
-
// Licensed under the MIT
|
3478
|
+
// Licensed under the MIT License.
|
3324
3479
|
const logger$5 = credentialLogger("DefaultAzureCredential");
|
3325
3480
|
/**
|
3326
3481
|
* Creates a {@link ManagedIdentityCredential} from the provided options.
|
@@ -3463,7 +3618,7 @@ class DefaultAzureCredential extends ChainedTokenCredential {
|
|
3463
3618
|
}
|
3464
3619
|
|
3465
3620
|
// Copyright (c) Microsoft Corporation.
|
3466
|
-
// Licensed under the MIT
|
3621
|
+
// Licensed under the MIT License.
|
3467
3622
|
const logger$4 = credentialLogger("InteractiveBrowserCredential");
|
3468
3623
|
/**
|
3469
3624
|
* Enables authentication to Microsoft Entra ID inside of the web browser
|
@@ -3529,7 +3684,7 @@ class InteractiveBrowserCredential {
|
|
3529
3684
|
* Authenticates with Microsoft Entra ID and returns an access token if successful.
|
3530
3685
|
* If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
|
3531
3686
|
*
|
3532
|
-
* If the token can't be retrieved silently, this method will
|
3687
|
+
* If the token can't be retrieved silently, this method will always generate a challenge for the user.
|
3533
3688
|
*
|
3534
3689
|
* On Node.js, this credential has [Proof Key for Code Exchange (PKCE)](https://datatracker.ietf.org/doc/html/rfc7636) enabled by default.
|
3535
3690
|
* PKCE is a security feature that mitigates authentication code interception attacks.
|
@@ -3548,7 +3703,7 @@ class InteractiveBrowserCredential {
|
|
3548
3703
|
}
|
3549
3704
|
|
3550
3705
|
// Copyright (c) Microsoft Corporation.
|
3551
|
-
// Licensed under the MIT
|
3706
|
+
// Licensed under the MIT License.
|
3552
3707
|
const logger$3 = credentialLogger("DeviceCodeCredential");
|
3553
3708
|
/**
|
3554
3709
|
* Method that logs the user code from the DeviceCodeCredential.
|
@@ -3615,7 +3770,7 @@ class DeviceCodeCredential {
|
|
3615
3770
|
* Authenticates with Microsoft Entra ID and returns an access token if successful.
|
3616
3771
|
* If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
|
3617
3772
|
*
|
3618
|
-
* If the token can't be retrieved silently, this method will
|
3773
|
+
* If the token can't be retrieved silently, this method will always generate a challenge for the user.
|
3619
3774
|
*
|
3620
3775
|
* @param scopes - The list of scopes for which the token will have access.
|
3621
3776
|
* @param options - The options used to configure any requests this
|
@@ -3631,7 +3786,7 @@ class DeviceCodeCredential {
|
|
3631
3786
|
}
|
3632
3787
|
|
3633
3788
|
// Copyright (c) Microsoft Corporation.
|
3634
|
-
// Licensed under the MIT
|
3789
|
+
// Licensed under the MIT License.
|
3635
3790
|
const credentialName$1 = "AzurePipelinesCredential";
|
3636
3791
|
const logger$2 = credentialLogger(credentialName$1);
|
3637
3792
|
const OIDC_API_VERSION = "7.1";
|
@@ -3649,8 +3804,17 @@ class AzurePipelinesCredential {
|
|
3649
3804
|
* @param options - The identity client options to use for authentication.
|
3650
3805
|
*/
|
3651
3806
|
constructor(tenantId, clientId, serviceConnectionId, systemAccessToken, options) {
|
3652
|
-
if (!clientId
|
3653
|
-
throw new CredentialUnavailableError(`${credentialName$1}: is unavailable.
|
3807
|
+
if (!clientId) {
|
3808
|
+
throw new CredentialUnavailableError(`${credentialName$1}: is unavailable. clientId is a required parameter.`);
|
3809
|
+
}
|
3810
|
+
if (!tenantId) {
|
3811
|
+
throw new CredentialUnavailableError(`${credentialName$1}: is unavailable. tenantId is a required parameter.`);
|
3812
|
+
}
|
3813
|
+
if (!serviceConnectionId) {
|
3814
|
+
throw new CredentialUnavailableError(`${credentialName$1}: is unavailable. serviceConnectionId is a required parameter.`);
|
3815
|
+
}
|
3816
|
+
if (!systemAccessToken) {
|
3817
|
+
throw new CredentialUnavailableError(`${credentialName$1}: is unavailable. systemAccessToken is a required parameter.`);
|
3654
3818
|
}
|
3655
3819
|
this.identityClient = new IdentityClient(options);
|
3656
3820
|
checkTenantId(logger$2, tenantId);
|
@@ -3703,35 +3867,50 @@ class AzurePipelinesCredential {
|
|
3703
3867
|
}),
|
3704
3868
|
});
|
3705
3869
|
const response = await this.identityClient.sendRequest(request);
|
3706
|
-
|
3707
|
-
|
3708
|
-
|
3709
|
-
|
3870
|
+
return handleOidcResponse(response);
|
3871
|
+
}
|
3872
|
+
}
|
3873
|
+
function handleOidcResponse(response) {
|
3874
|
+
const text = response.bodyAsText;
|
3875
|
+
if (!text) {
|
3876
|
+
logger$2.error(`${credentialName$1}: Authentication Failed. Received null token from OIDC request. Response status- ${response.status}. Complete response - ${JSON.stringify(response)}`);
|
3877
|
+
throw new AuthenticationError(response.status, {
|
3878
|
+
error: `${credentialName$1}: Authentication Failed. Received null token from OIDC request.`,
|
3879
|
+
error_description: `${JSON.stringify(response)}. See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/azurepipelinescredential/troubleshoot`,
|
3880
|
+
});
|
3881
|
+
}
|
3882
|
+
try {
|
3883
|
+
const result = JSON.parse(text);
|
3884
|
+
if (result === null || result === void 0 ? void 0 : result.oidcToken) {
|
3885
|
+
return result.oidcToken;
|
3710
3886
|
}
|
3711
|
-
|
3712
|
-
const
|
3713
|
-
|
3714
|
-
|
3715
|
-
|
3716
|
-
else {
|
3717
|
-
let errorMessage = `${credentialName$1}: Authentication Failed. oidcToken field not detected in the response.`;
|
3718
|
-
if (response.status !== 200) {
|
3719
|
-
errorMessage += `Response = ${JSON.stringify(result)}`;
|
3720
|
-
}
|
3721
|
-
logger$2.error(errorMessage);
|
3722
|
-
throw new AuthenticationError(response.status, errorMessage);
|
3887
|
+
else {
|
3888
|
+
const errorMessage = `${credentialName$1}: Authentication Failed. oidcToken field not detected in the response.`;
|
3889
|
+
let errorDescription = ``;
|
3890
|
+
if (response.status !== 200) {
|
3891
|
+
errorDescription = `Complete response - ${JSON.stringify(result)}. See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/azurepipelinescredential/troubleshoot`;
|
3723
3892
|
}
|
3724
|
-
|
3725
|
-
|
3726
|
-
|
3727
|
-
|
3728
|
-
|
3893
|
+
logger$2.error(errorMessage);
|
3894
|
+
logger$2.error(errorDescription);
|
3895
|
+
throw new AuthenticationError(response.status, {
|
3896
|
+
error: errorMessage,
|
3897
|
+
error_description: errorDescription,
|
3898
|
+
});
|
3729
3899
|
}
|
3730
3900
|
}
|
3901
|
+
catch (e) {
|
3902
|
+
const errorDetails = `${credentialName$1}: Authentication Failed. oidcToken field not detected in the response.`;
|
3903
|
+
logger$2.error(`Response from service = ${text} and error message = ${e.message}`);
|
3904
|
+
logger$2.error(errorDetails);
|
3905
|
+
throw new AuthenticationError(response.status, {
|
3906
|
+
error: errorDetails,
|
3907
|
+
error_description: `Response = ${text}. See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/azurepipelinescredential/troubleshoot`,
|
3908
|
+
});
|
3909
|
+
}
|
3731
3910
|
}
|
3732
3911
|
|
3733
3912
|
// Copyright (c) Microsoft Corporation.
|
3734
|
-
// Licensed under the MIT
|
3913
|
+
// Licensed under the MIT License.
|
3735
3914
|
const logger$1 = credentialLogger("AuthorizationCodeCredential");
|
3736
3915
|
/**
|
3737
3916
|
* Enables authentication to Microsoft Entra ID using an authorization code
|
@@ -3785,7 +3964,7 @@ class AuthorizationCodeCredential {
|
|
3785
3964
|
}
|
3786
3965
|
|
3787
3966
|
// Copyright (c) Microsoft Corporation.
|
3788
|
-
// Licensed under the MIT
|
3967
|
+
// Licensed under the MIT License.
|
3789
3968
|
const credentialName = "OnBehalfOfCredential";
|
3790
3969
|
const logger = credentialLogger(credentialName);
|
3791
3970
|
/**
|
@@ -3797,11 +3976,17 @@ class OnBehalfOfCredential {
|
|
3797
3976
|
const { certificatePath, sendCertificateChain } = options;
|
3798
3977
|
const { getAssertion } = options;
|
3799
3978
|
const { tenantId, clientId, userAssertionToken, additionallyAllowedTenants: additionallyAllowedTenantIds, } = options;
|
3800
|
-
if (!tenantId
|
3801
|
-
|
3802
|
-
|
3803
|
-
|
3804
|
-
throw new
|
3979
|
+
if (!tenantId) {
|
3980
|
+
throw new CredentialUnavailableError(`${credentialName}: tenantId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`);
|
3981
|
+
}
|
3982
|
+
if (!clientId) {
|
3983
|
+
throw new CredentialUnavailableError(`${credentialName}: clientId is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`);
|
3984
|
+
}
|
3985
|
+
if (!clientSecret && !certificatePath && !getAssertion) {
|
3986
|
+
throw new CredentialUnavailableError(`${credentialName}: You must provide one of clientSecret, certificatePath, or a getAssertion callback but none were provided. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`);
|
3987
|
+
}
|
3988
|
+
if (!userAssertionToken) {
|
3989
|
+
throw new CredentialUnavailableError(`${credentialName}: userAssertionToken is a required parameter. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.`);
|
3805
3990
|
}
|
3806
3991
|
this.certificatePath = certificatePath;
|
3807
3992
|
this.clientSecret = clientSecret;
|
@@ -3883,7 +4068,7 @@ class OnBehalfOfCredential {
|
|
3883
4068
|
}
|
3884
4069
|
|
3885
4070
|
// Copyright (c) Microsoft Corporation.
|
3886
|
-
// Licensed under the MIT
|
4071
|
+
// Licensed under the MIT License.
|
3887
4072
|
/**
|
3888
4073
|
* Returns a callback that provides a bearer token.
|
3889
4074
|
* For example, the bearer token can be used to authenticate a request as follows:
|
@@ -3934,7 +4119,7 @@ function getBearerTokenProvider(credential, scopes, options) {
|
|
3934
4119
|
}
|
3935
4120
|
|
3936
4121
|
// Copyright (c) Microsoft Corporation.
|
3937
|
-
// Licensed under the MIT
|
4122
|
+
// Licensed under the MIT License.
|
3938
4123
|
/**
|
3939
4124
|
* Returns a new instance of the {@link DefaultAzureCredential}.
|
3940
4125
|
*/
|