@azure/identity 2.1.0-alpha.20220609.3 → 2.1.0-alpha.20220708.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/README.md +24 -24
- package/dist/index.js +192 -103
- package/dist/index.js.map +1 -1
- package/dist-esm/src/client/identityClient.js +1 -1
- package/dist-esm/src/client/identityClient.js.map +1 -1
- package/dist-esm/src/constants.js +1 -1
- package/dist-esm/src/constants.js.map +1 -1
- package/dist-esm/src/credentials/authorizationCodeCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/authorizationCodeCredential.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/azurePowerShellCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/azurePowerShellCredential.js +1 -1
- package/dist-esm/src/credentials/azurePowerShellCredential.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 +22 -0
- package/dist-esm/src/credentials/clientAssertionCredential.browser.js.map +1 -0
- package/dist-esm/src/credentials/clientAssertionCredential.js +45 -0
- package/dist-esm/src/credentials/clientAssertionCredential.js.map +1 -0
- package/dist-esm/src/credentials/clientCertificateCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/clientSecretCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/deviceCodeCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/environmentCredential.js +1 -1
- package/dist-esm/src/credentials/environmentCredential.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2017.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/appServiceMsi2019.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/arcMsi.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/cloudShellMsi.js.map +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/index.js +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/tokenExchangeMsi.js.map +1 -1
- package/dist-esm/src/credentials/onBehalfOfCredential.browser.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/visualStudioCodeCredential.browser.js.map +1 -1
- package/dist-esm/src/credentials/visualStudioCodeCredential.js.map +1 -1
- package/dist-esm/src/index.js +1 -0
- package/dist-esm/src/index.js.map +1 -1
- package/dist-esm/src/msal/browserFlows/msalAuthCode.js.map +1 -1
- package/dist-esm/src/msal/browserFlows/msalBrowserCommon.js +1 -1
- package/dist-esm/src/msal/browserFlows/msalBrowserCommon.js.map +1 -1
- package/dist-esm/src/msal/credentials.js.map +1 -1
- package/dist-esm/src/msal/flows.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalAuthorizationCode.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalClientAssertion.js +42 -0
- package/dist-esm/src/msal/nodeFlows/msalClientAssertion.js.map +1 -0
- package/dist-esm/src/msal/nodeFlows/msalClientCertificate.js +3 -2
- package/dist-esm/src/msal/nodeFlows/msalClientCertificate.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalClientSecret.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalDeviceCode.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js +7 -1
- package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalOnBehalfOf.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js +2 -1
- package/dist-esm/src/msal/nodeFlows/msalOpenBrowser.js.map +1 -1
- package/dist-esm/src/msal/nodeFlows/msalUsernamePassword.js.map +1 -1
- package/dist-esm/src/msal/utils.js +1 -1
- package/dist-esm/src/msal/utils.js.map +1 -1
- package/dist-esm/src/util/logging.js.map +1 -1
- package/package.json +20 -14
- package/types/identity.d.ts +30 -0
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ var coreUtil = require('@azure/core-util');
|
|
|
8
8
|
var coreRestPipeline = require('@azure/core-rest-pipeline');
|
|
9
9
|
var abortController = require('@azure/abort-controller');
|
|
10
10
|
var coreTracing = require('@azure/core-tracing');
|
|
11
|
-
var logger$
|
|
11
|
+
var logger$m = require('@azure/logger');
|
|
12
12
|
var msalCommon = require('@azure/msal-common');
|
|
13
13
|
var uuid = require('uuid');
|
|
14
14
|
var fs = require('fs');
|
|
@@ -189,7 +189,7 @@ function getIdentityTokenEndpointSuffix(tenantId) {
|
|
|
189
189
|
/**
|
|
190
190
|
* Current version of the `@azure/identity` package.
|
|
191
191
|
*/
|
|
192
|
-
const SDK_VERSION = `2.1.0
|
|
192
|
+
const SDK_VERSION = `2.1.0`;
|
|
193
193
|
/**
|
|
194
194
|
* The default client ID for authentication
|
|
195
195
|
* @internal
|
|
@@ -245,7 +245,7 @@ const tracingClient = coreTracing.createTracingClient({
|
|
|
245
245
|
/**
|
|
246
246
|
* The AzureLogger used for all clients within the identity package
|
|
247
247
|
*/
|
|
248
|
-
const logger$
|
|
248
|
+
const logger$l = logger$m.createClientLogger("identity");
|
|
249
249
|
/**
|
|
250
250
|
* 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.
|
|
251
251
|
* @param supportedEnvVars - List of environment variable names
|
|
@@ -285,7 +285,7 @@ function formatError(scope, error) {
|
|
|
285
285
|
* `[title] => [message]`
|
|
286
286
|
*
|
|
287
287
|
*/
|
|
288
|
-
function credentialLoggerInstance(title, parent, log = logger$
|
|
288
|
+
function credentialLoggerInstance(title, parent, log = logger$l) {
|
|
289
289
|
const fullTitle = parent ? `${parent.fullTitle} ${title}` : title;
|
|
290
290
|
function info(message) {
|
|
291
291
|
log.info(`${fullTitle} =>`, message);
|
|
@@ -310,7 +310,7 @@ function credentialLoggerInstance(title, parent, log = logger$k) {
|
|
|
310
310
|
* `[title] => getToken() => [message]`
|
|
311
311
|
*
|
|
312
312
|
*/
|
|
313
|
-
function credentialLogger(title, log = logger$
|
|
313
|
+
function credentialLogger(title, log = logger$l) {
|
|
314
314
|
const credLogger = credentialLoggerInstance(title, undefined, log);
|
|
315
315
|
return Object.assign(Object.assign({}, credLogger), { parent: log, getToken: credentialLoggerInstance("=> getToken()", credLogger, log) });
|
|
316
316
|
}
|
|
@@ -358,7 +358,7 @@ class IdentityClient extends coreClient.ServiceClient {
|
|
|
358
358
|
this.allowLoggingAccountIdentifiers = (_b = options === null || options === void 0 ? void 0 : options.loggingOptions) === null || _b === void 0 ? void 0 : _b.allowLoggingAccountIdentifiers;
|
|
359
359
|
}
|
|
360
360
|
async sendTokenRequest(request, expiresOnParser) {
|
|
361
|
-
logger$
|
|
361
|
+
logger$l.info(`IdentityClient: sending token request to [${request.url}]`);
|
|
362
362
|
const response = await this.sendRequest(request);
|
|
363
363
|
expiresOnParser =
|
|
364
364
|
expiresOnParser ||
|
|
@@ -378,12 +378,12 @@ class IdentityClient extends coreClient.ServiceClient {
|
|
|
378
378
|
},
|
|
379
379
|
refreshToken: parsedBody.refresh_token,
|
|
380
380
|
};
|
|
381
|
-
logger$
|
|
381
|
+
logger$l.info(`IdentityClient: [${request.url}] token acquired, expires on ${token.accessToken.expiresOnTimestamp}`);
|
|
382
382
|
return token;
|
|
383
383
|
}
|
|
384
384
|
else {
|
|
385
385
|
const error = new AuthenticationError(response.status, response.bodyAsText);
|
|
386
|
-
logger$
|
|
386
|
+
logger$l.warning(`IdentityClient: authentication error. HTTP status: ${response.status}, ${error.errorResponse.errorDescription}`);
|
|
387
387
|
throw error;
|
|
388
388
|
}
|
|
389
389
|
}
|
|
@@ -391,7 +391,7 @@ class IdentityClient extends coreClient.ServiceClient {
|
|
|
391
391
|
if (refreshToken === undefined) {
|
|
392
392
|
return null;
|
|
393
393
|
}
|
|
394
|
-
logger$
|
|
394
|
+
logger$l.info(`IdentityClient: refreshing access token with client ID: ${clientId}, scopes: ${scopes} started`);
|
|
395
395
|
const refreshParams = {
|
|
396
396
|
grant_type: "refresh_token",
|
|
397
397
|
client_id: clientId,
|
|
@@ -417,7 +417,7 @@ class IdentityClient extends coreClient.ServiceClient {
|
|
|
417
417
|
tracingOptions: updatedOptions.tracingOptions,
|
|
418
418
|
});
|
|
419
419
|
const response = await this.sendTokenRequest(request, expiresOnParser);
|
|
420
|
-
logger$
|
|
420
|
+
logger$l.info(`IdentityClient: refreshed token for client ID: ${clientId}`);
|
|
421
421
|
return response;
|
|
422
422
|
}
|
|
423
423
|
catch (err) {
|
|
@@ -426,11 +426,11 @@ class IdentityClient extends coreClient.ServiceClient {
|
|
|
426
426
|
// It's likely that the refresh token has expired, so
|
|
427
427
|
// return null so that the credential implementation will
|
|
428
428
|
// initiate the authentication flow again.
|
|
429
|
-
logger$
|
|
429
|
+
logger$l.info(`IdentityClient: interaction required for client ID: ${clientId}`);
|
|
430
430
|
return null;
|
|
431
431
|
}
|
|
432
432
|
else {
|
|
433
|
-
logger$
|
|
433
|
+
logger$l.warning(`IdentityClient: failed refreshing token for client ID: ${clientId}: ${err}`);
|
|
434
434
|
throw err;
|
|
435
435
|
}
|
|
436
436
|
}
|
|
@@ -532,10 +532,10 @@ class IdentityClient extends coreClient.ServiceClient {
|
|
|
532
532
|
}
|
|
533
533
|
const base64Metadata = accessToken.split(".")[1];
|
|
534
534
|
const { appid, upn, tid, oid } = JSON.parse(Buffer.from(base64Metadata, "base64").toString("utf8"));
|
|
535
|
-
logger$
|
|
535
|
+
logger$l.info(`[Authenticated account] Client ID: ${appid}. Tenant ID: ${tid}. User Principal Name: ${upn || unavailableUpn}. Object ID (user): ${oid}`);
|
|
536
536
|
}
|
|
537
537
|
catch (e) {
|
|
538
|
-
logger$
|
|
538
|
+
logger$l.warning("allowLoggingAccountIdentifiers was set, but we couldn't log the account information. Error:", e.message);
|
|
539
539
|
}
|
|
540
540
|
}
|
|
541
541
|
}
|
|
@@ -951,6 +951,9 @@ class MsalNode extends MsalBaseUtilities {
|
|
|
951
951
|
this.msalConfig = this.defaultNodeMsalConfig(options);
|
|
952
952
|
this.tenantId = resolveTenantId(options.logger, options.tenantId, options.clientId);
|
|
953
953
|
this.clientId = this.msalConfig.auth.clientId;
|
|
954
|
+
if (options === null || options === void 0 ? void 0 : options.getAssertion) {
|
|
955
|
+
this.getAssertion = options.getAssertion;
|
|
956
|
+
}
|
|
954
957
|
// If persistence has been configured
|
|
955
958
|
if (persistenceProvider !== undefined && ((_a = options.tokenCachePersistenceOptions) === null || _a === void 0 ? void 0 : _a.enabled)) {
|
|
956
959
|
this.createCachePlugin = () => persistenceProvider(options.tokenCachePersistenceOptions);
|
|
@@ -1017,6 +1020,9 @@ class MsalNode extends MsalBaseUtilities {
|
|
|
1017
1020
|
};
|
|
1018
1021
|
}
|
|
1019
1022
|
this.publicApp = new msalNode__namespace.PublicClientApplication(this.msalConfig);
|
|
1023
|
+
if (this.getAssertion) {
|
|
1024
|
+
this.msalConfig.auth.clientAssertion = await this.getAssertion();
|
|
1025
|
+
}
|
|
1020
1026
|
// The confidential client requires either a secret, assertion or certificate.
|
|
1021
1027
|
if (this.msalConfig.auth.clientSecret ||
|
|
1022
1028
|
this.msalConfig.auth.clientAssertion ||
|
|
@@ -1146,7 +1152,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
|
1146
1152
|
// Copyright (c) Microsoft Corporation.
|
|
1147
1153
|
const CommonTenantId = "common";
|
|
1148
1154
|
const AzureAccountClientId = "aebc6443-996d-45c2-90f0-388ff96faa56"; // VSC: 'aebc6443-996d-45c2-90f0-388ff96faa56'
|
|
1149
|
-
const logger$
|
|
1155
|
+
const logger$k = credentialLogger("VisualStudioCodeCredential");
|
|
1150
1156
|
let findCredentials = undefined;
|
|
1151
1157
|
const vsCodeCredentialControl = {
|
|
1152
1158
|
setVsCodeCredentialFinder(finder) {
|
|
@@ -1199,7 +1205,7 @@ function getPropertyFromVSCode(property) {
|
|
|
1199
1205
|
}
|
|
1200
1206
|
}
|
|
1201
1207
|
catch (e) {
|
|
1202
|
-
logger$
|
|
1208
|
+
logger$k.info(`Failed to load the Visual Studio Code configuration file. Error: ${e.message}`);
|
|
1203
1209
|
return;
|
|
1204
1210
|
}
|
|
1205
1211
|
}
|
|
@@ -1227,7 +1233,7 @@ class VisualStudioCodeCredential {
|
|
|
1227
1233
|
const authorityHost = mapVSCodeAuthorityHosts[this.cloudName];
|
|
1228
1234
|
this.identityClient = new IdentityClient(Object.assign({ authorityHost }, options));
|
|
1229
1235
|
if (options && options.tenantId) {
|
|
1230
|
-
checkTenantId(logger$
|
|
1236
|
+
checkTenantId(logger$k, options.tenantId);
|
|
1231
1237
|
this.tenantId = options.tenantId;
|
|
1232
1238
|
}
|
|
1233
1239
|
else {
|
|
@@ -1279,7 +1285,7 @@ class VisualStudioCodeCredential {
|
|
|
1279
1285
|
// Check to make sure the scope we get back is a valid scope
|
|
1280
1286
|
if (!scopeString.match(/^[0-9a-zA-Z-.:/]+$/)) {
|
|
1281
1287
|
const error = new Error("Invalid scope was specified by the user or calling client");
|
|
1282
|
-
logger$
|
|
1288
|
+
logger$k.getToken.info(formatError(scopes, error));
|
|
1283
1289
|
throw error;
|
|
1284
1290
|
}
|
|
1285
1291
|
if (scopeString.indexOf("offline_access") < 0) {
|
|
@@ -1299,18 +1305,18 @@ class VisualStudioCodeCredential {
|
|
|
1299
1305
|
if (refreshToken) {
|
|
1300
1306
|
const tokenResponse = await this.identityClient.refreshAccessToken(tenantId, AzureAccountClientId, scopeString, refreshToken, undefined);
|
|
1301
1307
|
if (tokenResponse) {
|
|
1302
|
-
logger$
|
|
1308
|
+
logger$k.getToken.info(formatSuccess(scopes));
|
|
1303
1309
|
return tokenResponse.accessToken;
|
|
1304
1310
|
}
|
|
1305
1311
|
else {
|
|
1306
1312
|
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/vscodecredential/troubleshoot.");
|
|
1307
|
-
logger$
|
|
1313
|
+
logger$k.getToken.info(formatError(scopes, error));
|
|
1308
1314
|
throw error;
|
|
1309
1315
|
}
|
|
1310
1316
|
}
|
|
1311
1317
|
else {
|
|
1312
1318
|
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/vscodecredential/troubleshoot.");
|
|
1313
|
-
logger$
|
|
1319
|
+
logger$k.getToken.info(formatError(scopes, error));
|
|
1314
1320
|
throw error;
|
|
1315
1321
|
}
|
|
1316
1322
|
}
|
|
@@ -1361,7 +1367,7 @@ function useIdentityPlugin(plugin) {
|
|
|
1361
1367
|
/**
|
|
1362
1368
|
* @internal
|
|
1363
1369
|
*/
|
|
1364
|
-
const logger$
|
|
1370
|
+
const logger$j = credentialLogger("ChainedTokenCredential");
|
|
1365
1371
|
/**
|
|
1366
1372
|
* Enables multiple `TokenCredential` implementations to be tried in order
|
|
1367
1373
|
* until one of the getToken methods returns an access token.
|
|
@@ -1416,17 +1422,17 @@ class ChainedTokenCredential {
|
|
|
1416
1422
|
errors.push(err);
|
|
1417
1423
|
}
|
|
1418
1424
|
else {
|
|
1419
|
-
logger$
|
|
1425
|
+
logger$j.getToken.info(formatError(scopes, err));
|
|
1420
1426
|
throw err;
|
|
1421
1427
|
}
|
|
1422
1428
|
}
|
|
1423
1429
|
}
|
|
1424
1430
|
if (!token && errors.length > 0) {
|
|
1425
1431
|
const err = new AggregateAuthenticationError(errors, "ChainedTokenCredential authentication failed.");
|
|
1426
|
-
logger$
|
|
1432
|
+
logger$j.getToken.info(formatError(scopes, err));
|
|
1427
1433
|
throw err;
|
|
1428
1434
|
}
|
|
1429
|
-
logger$
|
|
1435
|
+
logger$j.getToken.info(`Result for ${successfulCredentialName}: ${formatSuccess(scopes)}`);
|
|
1430
1436
|
if (token === null) {
|
|
1431
1437
|
throw new CredentialUnavailableError("Failed to retrieve a valid token");
|
|
1432
1438
|
}
|
|
@@ -1505,7 +1511,7 @@ const cliCredentialInternals = {
|
|
|
1505
1511
|
});
|
|
1506
1512
|
},
|
|
1507
1513
|
};
|
|
1508
|
-
const logger$
|
|
1514
|
+
const logger$i = credentialLogger("AzureCliCredential");
|
|
1509
1515
|
/**
|
|
1510
1516
|
* This credential will use the currently logged-in user login information
|
|
1511
1517
|
* via the Azure CLI ('az') commandline tool.
|
|
@@ -1535,11 +1541,11 @@ class AzureCliCredential {
|
|
|
1535
1541
|
async getToken(scopes, options = {}) {
|
|
1536
1542
|
const tenantId = processMultiTenantRequest(this.tenantId, options);
|
|
1537
1543
|
if (tenantId) {
|
|
1538
|
-
checkTenantId(logger$
|
|
1544
|
+
checkTenantId(logger$i, tenantId);
|
|
1539
1545
|
}
|
|
1540
1546
|
const scope = typeof scopes === "string" ? scopes : scopes[0];
|
|
1541
|
-
logger$
|
|
1542
|
-
ensureValidScope(scope, logger$
|
|
1547
|
+
logger$i.getToken.info(`Using the scope ${scope}`);
|
|
1548
|
+
ensureValidScope(scope, logger$i);
|
|
1543
1549
|
const resource = getScopeResource(scope);
|
|
1544
1550
|
return tracingClient.withSpan(`${this.constructor.name}.getToken`, options, async () => {
|
|
1545
1551
|
var _a, _b, _c, _d;
|
|
@@ -1550,18 +1556,18 @@ class AzureCliCredential {
|
|
|
1550
1556
|
const isNotInstallError = ((_c = obj.stderr) === null || _c === void 0 ? void 0 : _c.match("az:(.*)not found")) || ((_d = obj.stderr) === null || _d === void 0 ? void 0 : _d.startsWith("'az' is not recognized"));
|
|
1551
1557
|
if (isNotInstallError) {
|
|
1552
1558
|
const error = new CredentialUnavailableError("Azure CLI could not be found. Please visit https://aka.ms/azure-cli for installation instructions and then, once installed, authenticate to your Azure account using 'az login'.");
|
|
1553
|
-
logger$
|
|
1559
|
+
logger$i.getToken.info(formatError(scopes, error));
|
|
1554
1560
|
throw error;
|
|
1555
1561
|
}
|
|
1556
1562
|
if (isLoginError) {
|
|
1557
1563
|
const error = new CredentialUnavailableError("Please run 'az login' from a command prompt to authenticate before using this credential.");
|
|
1558
|
-
logger$
|
|
1564
|
+
logger$i.getToken.info(formatError(scopes, error));
|
|
1559
1565
|
throw error;
|
|
1560
1566
|
}
|
|
1561
1567
|
try {
|
|
1562
1568
|
const responseData = obj.stdout;
|
|
1563
1569
|
const response = JSON.parse(responseData);
|
|
1564
|
-
logger$
|
|
1570
|
+
logger$i.getToken.info(formatSuccess(scopes));
|
|
1565
1571
|
const returnValue = {
|
|
1566
1572
|
token: response.accessToken,
|
|
1567
1573
|
expiresOnTimestamp: new Date(response.expiresOn).getTime(),
|
|
@@ -1579,7 +1585,7 @@ class AzureCliCredential {
|
|
|
1579
1585
|
const error = err.name === "CredentialUnavailableError"
|
|
1580
1586
|
? err
|
|
1581
1587
|
: new Error(err.message || "Unknown error while trying to retrieve the access token");
|
|
1582
|
-
logger$
|
|
1588
|
+
logger$i.getToken.info(formatError(scopes, error));
|
|
1583
1589
|
throw error;
|
|
1584
1590
|
}
|
|
1585
1591
|
});
|
|
@@ -1617,7 +1623,7 @@ const processUtils = {
|
|
|
1617
1623
|
};
|
|
1618
1624
|
|
|
1619
1625
|
// Copyright (c) Microsoft Corporation.
|
|
1620
|
-
const logger$
|
|
1626
|
+
const logger$h = credentialLogger("AzurePowerShellCredential");
|
|
1621
1627
|
const isWindows = process.platform === "win32";
|
|
1622
1628
|
/**
|
|
1623
1629
|
* Returns a platform-appropriate command name by appending ".exe" on Windows.
|
|
@@ -1748,15 +1754,15 @@ class AzurePowerShellCredential {
|
|
|
1748
1754
|
return tracingClient.withSpan(`${this.constructor.name}.getToken`, options, async () => {
|
|
1749
1755
|
const tenantId = processMultiTenantRequest(this.tenantId, options);
|
|
1750
1756
|
if (tenantId) {
|
|
1751
|
-
checkTenantId(logger$
|
|
1757
|
+
checkTenantId(logger$h, tenantId);
|
|
1752
1758
|
}
|
|
1753
1759
|
const scope = typeof scopes === "string" ? scopes : scopes[0];
|
|
1754
|
-
ensureValidScope(scope, logger$
|
|
1755
|
-
logger$
|
|
1760
|
+
ensureValidScope(scope, logger$h);
|
|
1761
|
+
logger$h.getToken.info(`Using the scope ${scope}`);
|
|
1756
1762
|
const resource = getScopeResource(scope);
|
|
1757
1763
|
try {
|
|
1758
1764
|
const response = await this.getAzurePowerShellAccessToken(resource, tenantId);
|
|
1759
|
-
logger$
|
|
1765
|
+
logger$h.getToken.info(formatSuccess(scopes));
|
|
1760
1766
|
return {
|
|
1761
1767
|
token: response.Token,
|
|
1762
1768
|
expiresOnTimestamp: new Date(response.ExpiresOn).getTime(),
|
|
@@ -1765,16 +1771,16 @@ class AzurePowerShellCredential {
|
|
|
1765
1771
|
catch (err) {
|
|
1766
1772
|
if (isNotInstalledError(err)) {
|
|
1767
1773
|
const error = new CredentialUnavailableError(powerShellPublicErrorMessages.installed);
|
|
1768
|
-
logger$
|
|
1774
|
+
logger$h.getToken.info(formatError(scope, error));
|
|
1769
1775
|
throw error;
|
|
1770
1776
|
}
|
|
1771
1777
|
else if (isLoginError(err)) {
|
|
1772
1778
|
const error = new CredentialUnavailableError(powerShellPublicErrorMessages.login);
|
|
1773
|
-
logger$
|
|
1779
|
+
logger$h.getToken.info(formatError(scope, error));
|
|
1774
1780
|
throw error;
|
|
1775
1781
|
}
|
|
1776
1782
|
const error = new CredentialUnavailableError(`${err}. ${powerShellPublicErrorMessages.troubleshoot}`);
|
|
1777
|
-
logger$
|
|
1783
|
+
logger$h.getToken.info(formatError(scope, error));
|
|
1778
1784
|
throw error;
|
|
1779
1785
|
}
|
|
1780
1786
|
});
|
|
@@ -1812,7 +1818,7 @@ class MsalClientSecret extends MsalNode {
|
|
|
1812
1818
|
}
|
|
1813
1819
|
|
|
1814
1820
|
// Copyright (c) Microsoft Corporation.
|
|
1815
|
-
const logger$
|
|
1821
|
+
const logger$g = credentialLogger("ClientSecretCredential");
|
|
1816
1822
|
/**
|
|
1817
1823
|
* Enables authentication to Azure Active Directory using a client secret
|
|
1818
1824
|
* that was generated for an App Registration. More information on how
|
|
@@ -1836,7 +1842,7 @@ class ClientSecretCredential {
|
|
|
1836
1842
|
if (!tenantId || !clientId || !clientSecret) {
|
|
1837
1843
|
throw new Error("ClientSecretCredential: tenantId, clientId, and clientSecret are required parameters. To troubleshoot, visit https://aka.ms/azsdk/js/identity/serviceprincipalauthentication/troubleshoot.");
|
|
1838
1844
|
}
|
|
1839
|
-
this.msalFlow = new MsalClientSecret(Object.assign(Object.assign({}, options), { logger: logger$
|
|
1845
|
+
this.msalFlow = new MsalClientSecret(Object.assign(Object.assign({}, options), { logger: logger$g,
|
|
1840
1846
|
clientId,
|
|
1841
1847
|
tenantId,
|
|
1842
1848
|
clientSecret, tokenCredentialOptions: options }));
|
|
@@ -1926,13 +1932,14 @@ class MsalClientCertificate extends MsalNode {
|
|
|
1926
1932
|
}
|
|
1927
1933
|
async doGetToken(scopes, options = {}) {
|
|
1928
1934
|
try {
|
|
1929
|
-
const
|
|
1935
|
+
const clientCredReq = {
|
|
1930
1936
|
scopes,
|
|
1931
1937
|
correlationId: options.correlationId,
|
|
1932
1938
|
azureRegion: this.azureRegion,
|
|
1933
1939
|
authority: options.authority,
|
|
1934
1940
|
claims: options.claims,
|
|
1935
|
-
}
|
|
1941
|
+
};
|
|
1942
|
+
const result = await this.confidentialApp.acquireTokenByClientCredential(clientCredReq);
|
|
1936
1943
|
// Even though we're providing the same default in memory persistence cache that we use for DeviceCodeCredential,
|
|
1937
1944
|
// The Client Credential flow does not return the account information from the authentication service,
|
|
1938
1945
|
// so each time getToken gets called, we will have to acquire a new token through the service.
|
|
@@ -1946,7 +1953,7 @@ class MsalClientCertificate extends MsalNode {
|
|
|
1946
1953
|
|
|
1947
1954
|
// Copyright (c) Microsoft Corporation.
|
|
1948
1955
|
const credentialName$2 = "ClientCertificateCredential";
|
|
1949
|
-
const logger$
|
|
1956
|
+
const logger$f = credentialLogger(credentialName$2);
|
|
1950
1957
|
/**
|
|
1951
1958
|
* Enables authentication to Azure Active Directory using a PEM-encoded
|
|
1952
1959
|
* certificate that is assigned to an App Registration. More information
|
|
@@ -1975,7 +1982,7 @@ class ClientCertificateCredential {
|
|
|
1975
1982
|
throw new Error(`${credentialName$2}: 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.`);
|
|
1976
1983
|
}
|
|
1977
1984
|
this.msalFlow = new MsalClientCertificate(Object.assign(Object.assign({}, options), { configuration,
|
|
1978
|
-
logger: logger$
|
|
1985
|
+
logger: logger$f,
|
|
1979
1986
|
clientId,
|
|
1980
1987
|
tenantId, sendCertificateChain: options.sendCertificateChain, tokenCredentialOptions: options }));
|
|
1981
1988
|
}
|
|
@@ -2026,7 +2033,7 @@ class MsalUsernamePassword extends MsalNode {
|
|
|
2026
2033
|
}
|
|
2027
2034
|
|
|
2028
2035
|
// Copyright (c) Microsoft Corporation.
|
|
2029
|
-
const logger$
|
|
2036
|
+
const logger$e = credentialLogger("UsernamePasswordCredential");
|
|
2030
2037
|
/**
|
|
2031
2038
|
* Enables authentication to Azure Active Directory with a user's
|
|
2032
2039
|
* username and password. This credential requires a high degree of
|
|
@@ -2049,7 +2056,7 @@ class UsernamePasswordCredential {
|
|
|
2049
2056
|
if (!tenantId || !clientId || !username || !password) {
|
|
2050
2057
|
throw new Error("UsernamePasswordCredential: tenantId, clientId, username and password are required parameters. To troubleshoot, visit https://aka.ms/azsdk/js/identity/usernamepasswordcredential/troubleshoot.");
|
|
2051
2058
|
}
|
|
2052
|
-
this.msalFlow = new MsalUsernamePassword(Object.assign(Object.assign({}, options), { logger: logger$
|
|
2059
|
+
this.msalFlow = new MsalUsernamePassword(Object.assign(Object.assign({}, options), { logger: logger$e,
|
|
2053
2060
|
clientId,
|
|
2054
2061
|
tenantId,
|
|
2055
2062
|
username,
|
|
@@ -2092,7 +2099,7 @@ const AllSupportedEnvironmentVariables = [
|
|
|
2092
2099
|
"AZURE_PASSWORD",
|
|
2093
2100
|
];
|
|
2094
2101
|
const credentialName$1 = "EnvironmentCredential";
|
|
2095
|
-
const logger$
|
|
2102
|
+
const logger$d = credentialLogger(credentialName$1);
|
|
2096
2103
|
/**
|
|
2097
2104
|
* Enables authentication to Azure Active Directory using client secret
|
|
2098
2105
|
* details configured in environment variables
|
|
@@ -2122,26 +2129,26 @@ class EnvironmentCredential {
|
|
|
2122
2129
|
// Keep track of any missing environment variables for error details
|
|
2123
2130
|
this._credential = undefined;
|
|
2124
2131
|
const assigned = processEnvVars(AllSupportedEnvironmentVariables).assigned.join(", ");
|
|
2125
|
-
logger$
|
|
2132
|
+
logger$d.info(`Found the following environment variables: ${assigned}`);
|
|
2126
2133
|
const tenantId = process.env.AZURE_TENANT_ID, clientId = process.env.AZURE_CLIENT_ID, clientSecret = process.env.AZURE_CLIENT_SECRET;
|
|
2127
2134
|
if (tenantId) {
|
|
2128
|
-
checkTenantId(logger$
|
|
2135
|
+
checkTenantId(logger$d, tenantId);
|
|
2129
2136
|
}
|
|
2130
2137
|
if (tenantId && clientId && clientSecret) {
|
|
2131
|
-
logger$
|
|
2138
|
+
logger$d.info(`Invoking ClientSecretCredential with tenant ID: ${tenantId}, clientId: ${clientId} and clientSecret: [REDACTED]`);
|
|
2132
2139
|
this._credential = new ClientSecretCredential(tenantId, clientId, clientSecret, options);
|
|
2133
2140
|
return;
|
|
2134
2141
|
}
|
|
2135
2142
|
const certificatePath = process.env.AZURE_CLIENT_CERTIFICATE_PATH;
|
|
2136
2143
|
if (tenantId && clientId && certificatePath) {
|
|
2137
|
-
logger$
|
|
2144
|
+
logger$d.info(`Invoking ClientCertificateCredential with tenant ID: ${tenantId}, clientId: ${clientId} and certificatePath: ${certificatePath}`);
|
|
2138
2145
|
this._credential = new ClientCertificateCredential(tenantId, clientId, { certificatePath }, options);
|
|
2139
2146
|
return;
|
|
2140
2147
|
}
|
|
2141
2148
|
const username = process.env.AZURE_USERNAME;
|
|
2142
2149
|
const password = process.env.AZURE_PASSWORD;
|
|
2143
2150
|
if (tenantId && clientId && username && password) {
|
|
2144
|
-
logger$
|
|
2151
|
+
logger$d.info(`Invoking UsernamePasswordCredential with tenant ID: ${tenantId}, clientId: ${clientId} and username: ${username}`);
|
|
2145
2152
|
this._credential = new UsernamePasswordCredential(tenantId, clientId, username, password, options);
|
|
2146
2153
|
}
|
|
2147
2154
|
}
|
|
@@ -2156,7 +2163,7 @@ class EnvironmentCredential {
|
|
|
2156
2163
|
if (this._credential) {
|
|
2157
2164
|
try {
|
|
2158
2165
|
const result = await this._credential.getToken(scopes, newOptions);
|
|
2159
|
-
logger$
|
|
2166
|
+
logger$d.getToken.info(formatSuccess(scopes));
|
|
2160
2167
|
return result;
|
|
2161
2168
|
}
|
|
2162
2169
|
catch (err) {
|
|
@@ -2164,7 +2171,7 @@ class EnvironmentCredential {
|
|
|
2164
2171
|
error: `${credentialName$1} authentication failed. To troubleshoot, visit https://aka.ms/azsdk/js/identity/environmentcredential/troubleshoot.`,
|
|
2165
2172
|
error_description: err.message.toString().split("More details:").join(""),
|
|
2166
2173
|
});
|
|
2167
|
-
logger$
|
|
2174
|
+
logger$d.getToken.info(formatError(scopes, authenticationError));
|
|
2168
2175
|
throw authenticationError;
|
|
2169
2176
|
}
|
|
2170
2177
|
}
|
|
@@ -2211,7 +2218,7 @@ function mapScopesToResource(scopes) {
|
|
|
2211
2218
|
|
|
2212
2219
|
// Copyright (c) Microsoft Corporation.
|
|
2213
2220
|
const msiName$6 = "ManagedIdentityCredential - AppServiceMSI 2017";
|
|
2214
|
-
const logger$
|
|
2221
|
+
const logger$c = credentialLogger(msiName$6);
|
|
2215
2222
|
/**
|
|
2216
2223
|
* Formats the expiration date of the received token into the number of milliseconds between that date and midnight, January 1, 1970.
|
|
2217
2224
|
*/
|
|
@@ -2258,22 +2265,22 @@ const appServiceMsi2017 = {
|
|
|
2258
2265
|
async isAvailable({ scopes }) {
|
|
2259
2266
|
const resource = mapScopesToResource(scopes);
|
|
2260
2267
|
if (!resource) {
|
|
2261
|
-
logger$
|
|
2268
|
+
logger$c.info(`${msiName$6}: Unavailable. Multiple scopes are not supported.`);
|
|
2262
2269
|
return false;
|
|
2263
2270
|
}
|
|
2264
2271
|
const env = process.env;
|
|
2265
2272
|
const result = Boolean(env.MSI_ENDPOINT && env.MSI_SECRET);
|
|
2266
2273
|
if (!result) {
|
|
2267
|
-
logger$
|
|
2274
|
+
logger$c.info(`${msiName$6}: Unavailable. The environment variables needed are: MSI_ENDPOINT and MSI_SECRET.`);
|
|
2268
2275
|
}
|
|
2269
2276
|
return result;
|
|
2270
2277
|
},
|
|
2271
2278
|
async getToken(configuration, getTokenOptions = {}) {
|
|
2272
2279
|
const { identityClient, scopes, clientId, resourceId } = configuration;
|
|
2273
2280
|
if (resourceId) {
|
|
2274
|
-
logger$
|
|
2281
|
+
logger$c.warning(`${msiName$6}: managed Identity by resource Id is not supported. Argument resourceId might be ignored by the service.`);
|
|
2275
2282
|
}
|
|
2276
|
-
logger$
|
|
2283
|
+
logger$c.info(`${msiName$6}: Using the endpoint and the secret coming form the environment variables: MSI_ENDPOINT=${process.env.MSI_ENDPOINT} and MSI_SECRET=[REDACTED].`);
|
|
2277
2284
|
const request = coreRestPipeline.createPipelineRequest(Object.assign(Object.assign({ abortSignal: getTokenOptions.abortSignal }, prepareRequestOptions$6(scopes, clientId)), {
|
|
2278
2285
|
// Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).
|
|
2279
2286
|
allowInsecureConnection: true }));
|
|
@@ -2284,7 +2291,7 @@ const appServiceMsi2017 = {
|
|
|
2284
2291
|
|
|
2285
2292
|
// Copyright (c) Microsoft Corporation.
|
|
2286
2293
|
const msiName$5 = "ManagedIdentityCredential - CloudShellMSI";
|
|
2287
|
-
const logger$
|
|
2294
|
+
const logger$b = credentialLogger(msiName$5);
|
|
2288
2295
|
/**
|
|
2289
2296
|
* Generates the options used on the request for an access token.
|
|
2290
2297
|
*/
|
|
@@ -2326,24 +2333,24 @@ const cloudShellMsi = {
|
|
|
2326
2333
|
async isAvailable({ scopes }) {
|
|
2327
2334
|
const resource = mapScopesToResource(scopes);
|
|
2328
2335
|
if (!resource) {
|
|
2329
|
-
logger$
|
|
2336
|
+
logger$b.info(`${msiName$5}: Unavailable. Multiple scopes are not supported.`);
|
|
2330
2337
|
return false;
|
|
2331
2338
|
}
|
|
2332
2339
|
const result = Boolean(process.env.MSI_ENDPOINT);
|
|
2333
2340
|
if (!result) {
|
|
2334
|
-
logger$
|
|
2341
|
+
logger$b.info(`${msiName$5}: Unavailable. The environment variable MSI_ENDPOINT is needed.`);
|
|
2335
2342
|
}
|
|
2336
2343
|
return result;
|
|
2337
2344
|
},
|
|
2338
2345
|
async getToken(configuration, getTokenOptions = {}) {
|
|
2339
2346
|
const { identityClient, scopes, clientId, resourceId } = configuration;
|
|
2340
2347
|
if (clientId) {
|
|
2341
|
-
logger$
|
|
2348
|
+
logger$b.warning(`${msiName$5}: user-assigned identities not supported. The argument clientId might be ignored by the service.`);
|
|
2342
2349
|
}
|
|
2343
2350
|
if (resourceId) {
|
|
2344
|
-
logger$
|
|
2351
|
+
logger$b.warning(`${msiName$5}: user defined managed Identity by resource Id not supported. The argument resourceId might be ignored by the service.`);
|
|
2345
2352
|
}
|
|
2346
|
-
logger$
|
|
2353
|
+
logger$b.info(`${msiName$5}: Using the endpoint coming form the environment variable MSI_ENDPOINT = ${process.env.MSI_ENDPOINT}.`);
|
|
2347
2354
|
const request = coreRestPipeline.createPipelineRequest(Object.assign(Object.assign({ abortSignal: getTokenOptions.abortSignal }, prepareRequestOptions$5(scopes, clientId, resourceId)), {
|
|
2348
2355
|
// Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).
|
|
2349
2356
|
allowInsecureConnection: true }));
|
|
@@ -2354,7 +2361,7 @@ const cloudShellMsi = {
|
|
|
2354
2361
|
|
|
2355
2362
|
// Copyright (c) Microsoft Corporation.
|
|
2356
2363
|
const msiName$4 = "ManagedIdentityCredential - IMDS";
|
|
2357
|
-
const logger$
|
|
2364
|
+
const logger$a = credentialLogger(msiName$4);
|
|
2358
2365
|
/**
|
|
2359
2366
|
* Formats the expiration date of the received token into the number of milliseconds between that date and midnight, January 1, 1970.
|
|
2360
2367
|
*/
|
|
@@ -2362,13 +2369,13 @@ function expiresOnParser$2(requestBody) {
|
|
|
2362
2369
|
if (requestBody.expires_on) {
|
|
2363
2370
|
// Use the expires_on timestamp if it's available
|
|
2364
2371
|
const expires = +requestBody.expires_on * 1000;
|
|
2365
|
-
logger$
|
|
2372
|
+
logger$a.info(`${msiName$4}: Using expires_on: ${expires} (original value: ${requestBody.expires_on})`);
|
|
2366
2373
|
return expires;
|
|
2367
2374
|
}
|
|
2368
2375
|
else {
|
|
2369
2376
|
// If these aren't possible, use expires_in and calculate a timestamp
|
|
2370
2377
|
const expires = Date.now() + requestBody.expires_in * 1000;
|
|
2371
|
-
logger$
|
|
2378
|
+
logger$a.info(`${msiName$4}: IMDS using expires_in: ${expires} (original value: ${requestBody.expires_in})`);
|
|
2372
2379
|
return expires;
|
|
2373
2380
|
}
|
|
2374
2381
|
}
|
|
@@ -2428,7 +2435,7 @@ const imdsMsi = {
|
|
|
2428
2435
|
async isAvailable({ scopes, identityClient, clientId, resourceId, getTokenOptions = {}, }) {
|
|
2429
2436
|
const resource = mapScopesToResource(scopes);
|
|
2430
2437
|
if (!resource) {
|
|
2431
|
-
logger$
|
|
2438
|
+
logger$a.info(`${msiName$4}: Unavailable. Multiple scopes are not supported.`);
|
|
2432
2439
|
return false;
|
|
2433
2440
|
}
|
|
2434
2441
|
// if the PodIdentityEndpoint environment variable was set no need to probe the endpoint, it can be assumed to exist
|
|
@@ -2454,7 +2461,7 @@ const imdsMsi = {
|
|
|
2454
2461
|
// This MSI uses the imdsEndpoint to get the token, which only uses http://
|
|
2455
2462
|
request.allowInsecureConnection = true;
|
|
2456
2463
|
try {
|
|
2457
|
-
logger$
|
|
2464
|
+
logger$a.info(`${msiName$4}: Pinging the Azure IMDS endpoint`);
|
|
2458
2465
|
await identityClient.sendRequest(request);
|
|
2459
2466
|
}
|
|
2460
2467
|
catch (err) {
|
|
@@ -2466,25 +2473,25 @@ const imdsMsi = {
|
|
|
2466
2473
|
) {
|
|
2467
2474
|
// If the request failed, or Node.js was unable to establish a connection,
|
|
2468
2475
|
// or the host was down, we'll assume the IMDS endpoint isn't available.
|
|
2469
|
-
logger$
|
|
2476
|
+
logger$a.info(`${msiName$4}: The Azure IMDS endpoint is unavailable`);
|
|
2470
2477
|
return false;
|
|
2471
2478
|
}
|
|
2472
2479
|
}
|
|
2473
2480
|
// If we received any response, the endpoint is available
|
|
2474
|
-
logger$
|
|
2481
|
+
logger$a.info(`${msiName$4}: The Azure IMDS endpoint is available`);
|
|
2475
2482
|
return true;
|
|
2476
2483
|
}
|
|
2477
2484
|
catch (err) {
|
|
2478
2485
|
// createWebResource failed.
|
|
2479
2486
|
// This error should bubble up to the user.
|
|
2480
|
-
logger$
|
|
2487
|
+
logger$a.info(`${msiName$4}: Error when creating the WebResource for the Azure IMDS endpoint: ${err.message}`);
|
|
2481
2488
|
throw err;
|
|
2482
2489
|
}
|
|
2483
2490
|
});
|
|
2484
2491
|
},
|
|
2485
2492
|
async getToken(configuration, getTokenOptions = {}) {
|
|
2486
2493
|
const { identityClient, scopes, clientId, resourceId } = configuration;
|
|
2487
|
-
logger$
|
|
2494
|
+
logger$a.info(`${msiName$4}: Using the Azure IMDS endpoint coming from the environment variable MSI_ENDPOINT=${process.env.MSI_ENDPOINT}, and using the cloud shell to proceed with the authentication.`);
|
|
2488
2495
|
let nextDelayInMs = imdsMsiRetryConfig.startDelayInMs;
|
|
2489
2496
|
for (let retries = 0; retries < imdsMsiRetryConfig.maxRetries; retries++) {
|
|
2490
2497
|
try {
|
|
@@ -2507,7 +2514,7 @@ const imdsMsi = {
|
|
|
2507
2514
|
|
|
2508
2515
|
// Copyright (c) Microsoft Corporation.
|
|
2509
2516
|
const msiName$3 = "ManagedIdentityCredential - Azure Arc MSI";
|
|
2510
|
-
const logger$
|
|
2517
|
+
const logger$9 = credentialLogger(msiName$3);
|
|
2511
2518
|
/**
|
|
2512
2519
|
* Generates the options used on the request for an access token.
|
|
2513
2520
|
*/
|
|
@@ -2580,12 +2587,12 @@ const arcMsi = {
|
|
|
2580
2587
|
async isAvailable({ scopes }) {
|
|
2581
2588
|
const resource = mapScopesToResource(scopes);
|
|
2582
2589
|
if (!resource) {
|
|
2583
|
-
logger$
|
|
2590
|
+
logger$9.info(`${msiName$3}: Unavailable. Multiple scopes are not supported.`);
|
|
2584
2591
|
return false;
|
|
2585
2592
|
}
|
|
2586
2593
|
const result = Boolean(process.env.IMDS_ENDPOINT && process.env.IDENTITY_ENDPOINT);
|
|
2587
2594
|
if (!result) {
|
|
2588
|
-
logger$
|
|
2595
|
+
logger$9.info(`${msiName$3}: The environment variables needed are: IMDS_ENDPOINT and IDENTITY_ENDPOINT`);
|
|
2589
2596
|
}
|
|
2590
2597
|
return result;
|
|
2591
2598
|
},
|
|
@@ -2593,12 +2600,12 @@ const arcMsi = {
|
|
|
2593
2600
|
var _a;
|
|
2594
2601
|
const { identityClient, scopes, clientId, resourceId } = configuration;
|
|
2595
2602
|
if (clientId) {
|
|
2596
|
-
logger$
|
|
2603
|
+
logger$9.warning(`${msiName$3}: user-assigned identities not supported. The argument clientId might be ignored by the service.`);
|
|
2597
2604
|
}
|
|
2598
2605
|
if (resourceId) {
|
|
2599
|
-
logger$
|
|
2606
|
+
logger$9.warning(`${msiName$3}: user defined managed Identity by resource Id is not supported. Argument resourceId will be ignored.`);
|
|
2600
2607
|
}
|
|
2601
|
-
logger$
|
|
2608
|
+
logger$9.info(`${msiName$3}: Authenticating.`);
|
|
2602
2609
|
const requestOptions = Object.assign(Object.assign({ disableJsonStringifyOnBody: true, deserializationMapper: undefined, abortSignal: getTokenOptions.abortSignal }, prepareRequestOptions$3(scopes, clientId, resourceId)), { allowInsecureConnection: true });
|
|
2603
2610
|
const filePath = await filePathRequest(identityClient, requestOptions);
|
|
2604
2611
|
if (!filePath) {
|
|
@@ -2616,7 +2623,7 @@ const arcMsi = {
|
|
|
2616
2623
|
|
|
2617
2624
|
// Copyright (c) Microsoft Corporation.
|
|
2618
2625
|
const msiName$2 = "ManagedIdentityCredential - Token Exchange";
|
|
2619
|
-
const logger$
|
|
2626
|
+
const logger$8 = credentialLogger(msiName$2);
|
|
2620
2627
|
const readFileAsync = util.promisify(fs__default["default"].readFile);
|
|
2621
2628
|
/**
|
|
2622
2629
|
* Generates the options used on the request for an access token.
|
|
@@ -2672,13 +2679,13 @@ function tokenExchangeMsi() {
|
|
|
2672
2679
|
const env = process.env;
|
|
2673
2680
|
const result = Boolean((clientId || env.AZURE_CLIENT_ID) && env.AZURE_TENANT_ID && azureFederatedTokenFilePath);
|
|
2674
2681
|
if (!result) {
|
|
2675
|
-
logger$
|
|
2682
|
+
logger$8.info(`${msiName$2}: Unavailable. The environment variables needed are: AZURE_CLIENT_ID (or the client ID sent through the parameters), AZURE_TENANT_ID and AZURE_FEDERATED_TOKEN_FILE`);
|
|
2676
2683
|
}
|
|
2677
2684
|
return result;
|
|
2678
2685
|
},
|
|
2679
2686
|
async getToken(configuration, getTokenOptions = {}) {
|
|
2680
2687
|
const { identityClient, scopes, clientId } = configuration;
|
|
2681
|
-
logger$
|
|
2688
|
+
logger$8.info(`${msiName$2}: Using the client assertion coming from environment variables.`);
|
|
2682
2689
|
let assertion;
|
|
2683
2690
|
try {
|
|
2684
2691
|
assertion = await readAssertion();
|
|
@@ -2707,7 +2714,7 @@ function tokenExchangeMsi() {
|
|
|
2707
2714
|
// curl --insecure $IDENTITY_ENDPOINT'?api-version=2019-07-01-preview&resource=https://vault.azure.net/' -H "Secret: $IDENTITY_HEADER"
|
|
2708
2715
|
//
|
|
2709
2716
|
const msiName$1 = "ManagedIdentityCredential - Fabric MSI";
|
|
2710
|
-
const logger$
|
|
2717
|
+
const logger$7 = credentialLogger(msiName$1);
|
|
2711
2718
|
/**
|
|
2712
2719
|
* Formats the expiration date of the received token into the number of milliseconds between that date and midnight, January 1, 1970.
|
|
2713
2720
|
*/
|
|
@@ -2757,22 +2764,22 @@ const fabricMsi = {
|
|
|
2757
2764
|
async isAvailable({ scopes }) {
|
|
2758
2765
|
const resource = mapScopesToResource(scopes);
|
|
2759
2766
|
if (!resource) {
|
|
2760
|
-
logger$
|
|
2767
|
+
logger$7.info(`${msiName$1}: Unavailable. Multiple scopes are not supported.`);
|
|
2761
2768
|
return false;
|
|
2762
2769
|
}
|
|
2763
2770
|
const env = process.env;
|
|
2764
2771
|
const result = Boolean(env.IDENTITY_ENDPOINT && env.IDENTITY_HEADER && env.IDENTITY_SERVER_THUMBPRINT);
|
|
2765
2772
|
if (!result) {
|
|
2766
|
-
logger$
|
|
2773
|
+
logger$7.info(`${msiName$1}: Unavailable. The environment variables needed are: IDENTITY_ENDPOINT, IDENTITY_HEADER and IDENTITY_SERVER_THUMBPRINT`);
|
|
2767
2774
|
}
|
|
2768
2775
|
return result;
|
|
2769
2776
|
},
|
|
2770
2777
|
async getToken(configuration, getTokenOptions = {}) {
|
|
2771
2778
|
const { scopes, identityClient, clientId, resourceId } = configuration;
|
|
2772
2779
|
if (resourceId) {
|
|
2773
|
-
logger$
|
|
2780
|
+
logger$7.warning(`${msiName$1}: user defined managed Identity by resource Id is not supported. Argument resourceId might be ignored by the service.`);
|
|
2774
2781
|
}
|
|
2775
|
-
logger$
|
|
2782
|
+
logger$7.info([
|
|
2776
2783
|
`${msiName$1}:`,
|
|
2777
2784
|
"Using the endpoint and the secret coming from the environment variables:",
|
|
2778
2785
|
`IDENTITY_ENDPOINT=${process.env.IDENTITY_ENDPOINT},`,
|
|
@@ -2792,7 +2799,7 @@ const fabricMsi = {
|
|
|
2792
2799
|
|
|
2793
2800
|
// Copyright (c) Microsoft Corporation.
|
|
2794
2801
|
const msiName = "ManagedIdentityCredential - AppServiceMSI 2019";
|
|
2795
|
-
const logger$
|
|
2802
|
+
const logger$6 = credentialLogger(msiName);
|
|
2796
2803
|
/**
|
|
2797
2804
|
* Formats the expiration date of the received token into the number of milliseconds between that date and midnight, January 1, 1970.
|
|
2798
2805
|
*/
|
|
@@ -2842,19 +2849,19 @@ const appServiceMsi2019 = {
|
|
|
2842
2849
|
async isAvailable({ scopes }) {
|
|
2843
2850
|
const resource = mapScopesToResource(scopes);
|
|
2844
2851
|
if (!resource) {
|
|
2845
|
-
logger$
|
|
2852
|
+
logger$6.info(`${msiName}: Unavailable. Multiple scopes are not supported.`);
|
|
2846
2853
|
return false;
|
|
2847
2854
|
}
|
|
2848
2855
|
const env = process.env;
|
|
2849
2856
|
const result = Boolean(env.IDENTITY_ENDPOINT && env.IDENTITY_HEADER);
|
|
2850
2857
|
if (!result) {
|
|
2851
|
-
logger$
|
|
2858
|
+
logger$6.info(`${msiName}: Unavailable. The environment variables needed are: IDENTITY_ENDPOINT and IDENTITY_HEADER.`);
|
|
2852
2859
|
}
|
|
2853
2860
|
return result;
|
|
2854
2861
|
},
|
|
2855
2862
|
async getToken(configuration, getTokenOptions = {}) {
|
|
2856
2863
|
const { identityClient, scopes, clientId, resourceId } = configuration;
|
|
2857
|
-
logger$
|
|
2864
|
+
logger$6.info(`${msiName}: Using the endpoint and the secret coming form the environment variables: IDENTITY_ENDPOINT=${process.env.IDENTITY_ENDPOINT} and IDENTITY_HEADER=[REDACTED].`);
|
|
2858
2865
|
const request = coreRestPipeline.createPipelineRequest(Object.assign(Object.assign({ abortSignal: getTokenOptions.abortSignal }, prepareRequestOptions(scopes, clientId, resourceId)), {
|
|
2859
2866
|
// Generally, MSI endpoints use the HTTP protocol, without transport layer security (TLS).
|
|
2860
2867
|
allowInsecureConnection: true }));
|
|
@@ -2864,7 +2871,7 @@ const appServiceMsi2019 = {
|
|
|
2864
2871
|
};
|
|
2865
2872
|
|
|
2866
2873
|
// Copyright (c) Microsoft Corporation.
|
|
2867
|
-
const logger$
|
|
2874
|
+
const logger$5 = credentialLogger("ManagedIdentityCredential");
|
|
2868
2875
|
/**
|
|
2869
2876
|
* Attempts authentication using a managed identity available at the deployment environment.
|
|
2870
2877
|
* This authentication type works in Azure VMs, App Service instances, Azure Functions applications,
|
|
@@ -2975,7 +2982,7 @@ class ManagedIdentityCredential {
|
|
|
2975
2982
|
// It also means that the endpoint answered with either 200 or 201 (see the sendTokenRequest method),
|
|
2976
2983
|
// yet we had no access token. For this reason, we'll throw once with a specific message:
|
|
2977
2984
|
const error = new CredentialUnavailableError("The managed identity endpoint was reached, yet no tokens were received.");
|
|
2978
|
-
logger$
|
|
2985
|
+
logger$5.getToken.info(formatError(scopes, error));
|
|
2979
2986
|
throw error;
|
|
2980
2987
|
}
|
|
2981
2988
|
// Since `authenticateManagedIdentity` didn't throw, and the result was not null,
|
|
@@ -2987,10 +2994,10 @@ class ManagedIdentityCredential {
|
|
|
2987
2994
|
// We've previously determined that the endpoint was unavailable,
|
|
2988
2995
|
// either because it was unreachable or permanently unable to authenticate.
|
|
2989
2996
|
const error = new CredentialUnavailableError("The managed identity endpoint is not currently available");
|
|
2990
|
-
logger$
|
|
2997
|
+
logger$5.getToken.info(formatError(scopes, error));
|
|
2991
2998
|
throw error;
|
|
2992
2999
|
}
|
|
2993
|
-
logger$
|
|
3000
|
+
logger$5.getToken.info(formatSuccess(scopes));
|
|
2994
3001
|
return result;
|
|
2995
3002
|
}
|
|
2996
3003
|
catch (err) {
|
|
@@ -3012,14 +3019,14 @@ class ManagedIdentityCredential {
|
|
|
3012
3019
|
// we can safely assume the credential is unavailable.
|
|
3013
3020
|
if (err.code === "ENETUNREACH") {
|
|
3014
3021
|
const error = new CredentialUnavailableError(`${ManagedIdentityCredential.name}: Unavailable. Network unreachable. Message: ${err.message}`);
|
|
3015
|
-
logger$
|
|
3022
|
+
logger$5.getToken.info(formatError(scopes, error));
|
|
3016
3023
|
throw error;
|
|
3017
3024
|
}
|
|
3018
3025
|
// If either the host was unreachable,
|
|
3019
3026
|
// we can safely assume the credential is unavailable.
|
|
3020
3027
|
if (err.code === "EHOSTUNREACH") {
|
|
3021
3028
|
const error = new CredentialUnavailableError(`${ManagedIdentityCredential.name}: Unavailable. No managed identity endpoint found. Message: ${err.message}`);
|
|
3022
|
-
logger$
|
|
3029
|
+
logger$5.getToken.info(formatError(scopes, error));
|
|
3023
3030
|
throw error;
|
|
3024
3031
|
}
|
|
3025
3032
|
// If err.statusCode has a value of 400, it comes from sendTokenRequest,
|
|
@@ -3092,6 +3099,86 @@ class DefaultAzureCredential extends ChainedTokenCredential {
|
|
|
3092
3099
|
}
|
|
3093
3100
|
}
|
|
3094
3101
|
|
|
3102
|
+
// Copyright (c) Microsoft Corporation.
|
|
3103
|
+
/**
|
|
3104
|
+
* MSAL client assertion client. Calls to MSAL's confidential application's `acquireTokenByClientCredential` during `doGetToken`.
|
|
3105
|
+
* @internal
|
|
3106
|
+
*/
|
|
3107
|
+
class MsalClientAssertion extends MsalNode {
|
|
3108
|
+
constructor(options) {
|
|
3109
|
+
super(options);
|
|
3110
|
+
this.requiresConfidential = true;
|
|
3111
|
+
this.getAssertion = options.getAssertion;
|
|
3112
|
+
}
|
|
3113
|
+
async doGetToken(scopes, options = {}) {
|
|
3114
|
+
try {
|
|
3115
|
+
const assertion = await this.getAssertion();
|
|
3116
|
+
const result = await this.confidentialApp.acquireTokenByClientCredential({
|
|
3117
|
+
scopes,
|
|
3118
|
+
correlationId: options.correlationId,
|
|
3119
|
+
azureRegion: this.azureRegion,
|
|
3120
|
+
authority: options.authority,
|
|
3121
|
+
claims: options.claims,
|
|
3122
|
+
clientAssertion: assertion,
|
|
3123
|
+
});
|
|
3124
|
+
// The Client Credential flow does not return an account,
|
|
3125
|
+
// so each time getToken gets called, we will have to acquire a new token through the service.
|
|
3126
|
+
return this.handleResult(scopes, this.clientId, result || undefined);
|
|
3127
|
+
}
|
|
3128
|
+
catch (err) {
|
|
3129
|
+
let err2 = err;
|
|
3130
|
+
if (err === null || err === undefined) {
|
|
3131
|
+
err2 = new Error(JSON.stringify(err));
|
|
3132
|
+
}
|
|
3133
|
+
else {
|
|
3134
|
+
err2 = coreUtil.isError(err) ? err : new Error(String(err));
|
|
3135
|
+
}
|
|
3136
|
+
throw this.handleError(scopes, err2, options);
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
}
|
|
3140
|
+
|
|
3141
|
+
// Copyright (c) Microsoft Corporation.
|
|
3142
|
+
const logger$4 = credentialLogger("ClientAssertionCredential");
|
|
3143
|
+
/**
|
|
3144
|
+
* Authenticates a service principal with a JWT assertion.
|
|
3145
|
+
*/
|
|
3146
|
+
class ClientAssertionCredential {
|
|
3147
|
+
/**
|
|
3148
|
+
* Creates an instance of the ClientAssertionCredential with the details
|
|
3149
|
+
* needed to authenticate against Azure Active Directory with a client
|
|
3150
|
+
* assertion provided by the developer through the `getAssertion` function parameter.
|
|
3151
|
+
*
|
|
3152
|
+
* @param tenantId - The Azure Active Directory tenant (directory) ID.
|
|
3153
|
+
* @param clientId - The client (application) ID of an App Registration in the tenant.
|
|
3154
|
+
* @param getAssertion - A function that retrieves the assertion for the credential to use.
|
|
3155
|
+
* @param options - Options for configuring the client which makes the authentication request.
|
|
3156
|
+
*/
|
|
3157
|
+
constructor(tenantId, clientId, getAssertion, options = {}) {
|
|
3158
|
+
if (!tenantId || !clientId || !getAssertion) {
|
|
3159
|
+
throw new Error("ClientAssertionCredential: tenantId, clientId, and clientAssertion are required parameters.");
|
|
3160
|
+
}
|
|
3161
|
+
this.tenantId = tenantId;
|
|
3162
|
+
this.clientId = clientId;
|
|
3163
|
+
this.options = options;
|
|
3164
|
+
this.msalFlow = new MsalClientAssertion(Object.assign(Object.assign({}, options), { logger: logger$4, clientId: this.clientId, tenantId: this.tenantId, tokenCredentialOptions: this.options, getAssertion }));
|
|
3165
|
+
}
|
|
3166
|
+
/**
|
|
3167
|
+
* Authenticates with Azure Active Directory and returns an access token if successful.
|
|
3168
|
+
* If authentication fails, a {@link CredentialUnavailableError} will be thrown with the details of the failure.
|
|
3169
|
+
*
|
|
3170
|
+
* @param scopes - The list of scopes for which the token will have access.
|
|
3171
|
+
* @param options - The options used to configure any requests this
|
|
3172
|
+
* TokenCredential implementation might make.
|
|
3173
|
+
*/
|
|
3174
|
+
async getToken(scopes, options = {}) {
|
|
3175
|
+
return tracingClient.withSpan(`${this.constructor.name}.getToken`, options, async (newOptions) => {
|
|
3176
|
+
const arrayScopes = Array.isArray(scopes) ? scopes : [scopes];
|
|
3177
|
+
return this.msalFlow.getToken(arrayScopes, newOptions);
|
|
3178
|
+
});
|
|
3179
|
+
}
|
|
3180
|
+
}
|
|
3181
|
+
|
|
3095
3182
|
// Copyright (c) Microsoft Corporation.
|
|
3096
3183
|
/**
|
|
3097
3184
|
* A call to open(), but mockable
|
|
@@ -3243,7 +3330,8 @@ class MsalOpenBrowser extends MsalNode {
|
|
|
3243
3330
|
};
|
|
3244
3331
|
const response = await this.publicApp.getAuthCodeUrl(authCodeUrlParameters);
|
|
3245
3332
|
try {
|
|
3246
|
-
|
|
3333
|
+
// A new instance on macOS only which allows it to not hang, does not fix the issue on linux
|
|
3334
|
+
await interactiveBrowserMockable.open(response, { wait: true, newInstance: true });
|
|
3247
3335
|
}
|
|
3248
3336
|
catch (e) {
|
|
3249
3337
|
throw new CredentialUnavailableError(`InteractiveBrowserCredential: Could not open a browser window. Error: ${e.message}`);
|
|
@@ -3618,6 +3706,7 @@ exports.AuthorizationCodeCredential = AuthorizationCodeCredential;
|
|
|
3618
3706
|
exports.AzureCliCredential = AzureCliCredential;
|
|
3619
3707
|
exports.AzurePowerShellCredential = AzurePowerShellCredential;
|
|
3620
3708
|
exports.ChainedTokenCredential = ChainedTokenCredential;
|
|
3709
|
+
exports.ClientAssertionCredential = ClientAssertionCredential;
|
|
3621
3710
|
exports.ClientCertificateCredential = ClientCertificateCredential;
|
|
3622
3711
|
exports.ClientSecretCredential = ClientSecretCredential;
|
|
3623
3712
|
exports.CredentialUnavailableError = CredentialUnavailableError;
|
|
@@ -3632,7 +3721,7 @@ exports.UsernamePasswordCredential = UsernamePasswordCredential;
|
|
|
3632
3721
|
exports.VisualStudioCodeCredential = VisualStudioCodeCredential;
|
|
3633
3722
|
exports.deserializeAuthenticationRecord = deserializeAuthenticationRecord;
|
|
3634
3723
|
exports.getDefaultAzureCredential = getDefaultAzureCredential;
|
|
3635
|
-
exports.logger = logger$
|
|
3724
|
+
exports.logger = logger$l;
|
|
3636
3725
|
exports.serializeAuthenticationRecord = serializeAuthenticationRecord;
|
|
3637
3726
|
exports.useIdentityPlugin = useIdentityPlugin;
|
|
3638
3727
|
//# sourceMappingURL=index.js.map
|