@azure/identity 3.2.0-beta.1 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of @azure/identity might be problematic. Click here for more details.
- package/README.md +11 -3
- package/dist/index.js +177 -87
- package/dist/index.js.map +1 -1
- package/dist-esm/src/client/identityClient.js +2 -2
- package/dist-esm/src/client/identityClient.js.map +1 -1
- package/dist-esm/src/constants.js +1 -1
- package/dist-esm/src/constants.js.map +1 -1
- package/dist-esm/src/credentials/authorityValidationOptions.js.map +1 -1
- package/dist-esm/src/credentials/azureCliCredential.js +4 -3
- package/dist-esm/src/credentials/azureCliCredential.js.map +1 -1
- package/dist-esm/src/credentials/azureCliCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/azureDeveloperCliCredential.js +39 -14
- package/dist-esm/src/credentials/azureDeveloperCliCredential.js.map +1 -1
- package/dist-esm/src/credentials/azureDeveloperCliCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/azurePowerShellCredential.js +9 -5
- package/dist-esm/src/credentials/azurePowerShellCredential.js.map +1 -1
- package/dist-esm/src/credentials/azurePowerShellCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/chainedTokenCredential.js +8 -4
- package/dist-esm/src/credentials/chainedTokenCredential.js.map +1 -1
- package/dist-esm/src/credentials/clientAssertionCredential.js.map +1 -1
- package/dist-esm/src/credentials/defaultAzureCredential.js +47 -4
- package/dist-esm/src/credentials/defaultAzureCredential.js.map +1 -1
- package/dist-esm/src/credentials/defaultAzureCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/interactiveBrowserCredentialOptions.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.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/index.js +27 -21
- package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/models.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 +1 -1
- package/dist-esm/src/credentials/managedIdentityCredential/utils.js.map +1 -1
- package/dist-esm/src/credentials/usernamePasswordCredentialOptions.js.map +1 -1
- package/dist-esm/src/credentials/workloadIdentityCredential.js +28 -29
- package/dist-esm/src/credentials/workloadIdentityCredential.js.map +1 -1
- package/dist-esm/src/credentials/workloadIdentityCredentialOptions.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/nodeFlows/msalNodeCommon.js +9 -2
- package/dist-esm/src/msal/nodeFlows/msalNodeCommon.js.map +1 -1
- package/dist-esm/src/msal/utils.js +1 -1
- package/dist-esm/src/msal/utils.js.map +1 -1
- package/package.json +3 -3
- package/types/identity.d.ts +104 -13
package/README.md
CHANGED
|
@@ -68,9 +68,9 @@ While we recommend using managed identity or service principal authentication in
|
|
|
68
68
|
|
|
69
69
|
Developers coding outside of an IDE can also use the [Azure Developer CLI][azure_developer_cli] to authenticate. Applications using the `DefaultAzureCredential` or the `AzureDeveloperCliCredential` can then use this account to authenticate calls in their application when running locally.
|
|
70
70
|
|
|
71
|
-
To authenticate with the [Azure Developer CLI][azure_developer_cli], users can run the command `azd login`. For users running on a system with a default web browser, the Azure Developer CLI will launch the browser to authenticate the user.
|
|
71
|
+
To authenticate with the [Azure Developer CLI][azure_developer_cli], users can run the command `azd auth login`. For users running on a system with a default web browser, the Azure Developer CLI will launch the browser to authenticate the user.
|
|
72
72
|
|
|
73
|
-
For systems without a default web browser, the `azd login --use-device-code` command will use the device code authentication flow.
|
|
73
|
+
For systems without a default web browser, the `azd auth login --use-device-code` command will use the device code authentication flow.
|
|
74
74
|
|
|
75
75
|
#### Authenticate via the Azure CLI
|
|
76
76
|
|
|
@@ -133,7 +133,7 @@ If used from Node.js, the `DefaultAzureCredential` will attempt to authenticate
|
|
|
133
133
|
1. **Environment** - The `DefaultAzureCredential` will read account information specified via [environment variables](#environment-variables) and use it to authenticate.
|
|
134
134
|
1. **Workload Identity** - If the application is deployed to Azure Kubernetes Service with Managed Identity enabled, `DefaultAzureCredential` will authenticate with it.
|
|
135
135
|
1. **Managed Identity** - If the application is deployed to an Azure host with Managed Identity enabled, the `DefaultAzureCredential` will authenticate with that account.
|
|
136
|
-
1. **Azure Developer CLI** - If the developer has authenticated an account via the Azure Developer CLI `azd login` command, the `DefaultAzureCredential` will authenticate with that account.
|
|
136
|
+
1. **Azure Developer CLI** - If the developer has authenticated an account via the Azure Developer CLI `azd auth login` command, the `DefaultAzureCredential` will authenticate with that account.
|
|
137
137
|
1. **Azure CLI** - If the developer has authenticated an account via the Azure CLI `az login` command, the `DefaultAzureCredential` will authenticate with that account.
|
|
138
138
|
1. **Azure PowerShell** - If the developer has authenticated using the Azure PowerShell module `Connect-AzAccount` command, the `DefaultAzureCredential` will authenticate with that account.
|
|
139
139
|
|
|
@@ -298,6 +298,14 @@ Not all credentials require this configuration. Credentials that authenticate th
|
|
|
298
298
|
|
|
299
299
|
Configuration is attempted in the above order. For example, if values for a client secret and certificate are both present, the client secret will be used.
|
|
300
300
|
|
|
301
|
+
## Token caching
|
|
302
|
+
Token caching is a feature provided by the Azure Identity library that allows apps to:
|
|
303
|
+
- Cache tokens in memory (default) and on disk (opt-in).
|
|
304
|
+
- Improve resilience and performance.
|
|
305
|
+
- Reduce the number of requests made to Azure AD to obtain access tokens.
|
|
306
|
+
|
|
307
|
+
The Azure Identity library offers both in-memory and persistent disk caching. For more details, see the [token caching documentation](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/TOKEN_CACHING.md).
|
|
308
|
+
|
|
301
309
|
## Troubleshooting
|
|
302
310
|
|
|
303
311
|
### Error handling
|
package/dist/index.js
CHANGED
|
@@ -257,7 +257,7 @@ function credentialLogger(title, log = logger$n) {
|
|
|
257
257
|
/**
|
|
258
258
|
* Current version of the `@azure/identity` package.
|
|
259
259
|
*/
|
|
260
|
-
const SDK_VERSION = `3.2.0
|
|
260
|
+
const SDK_VERSION = `3.2.0`;
|
|
261
261
|
/**
|
|
262
262
|
* The default client ID for authentication
|
|
263
263
|
* @internal
|
|
@@ -473,7 +473,7 @@ class MsalBaseUtilities {
|
|
|
473
473
|
}
|
|
474
474
|
// transformations.ts
|
|
475
475
|
function publicToMsal(account) {
|
|
476
|
-
const [environment] = account.authority.match(/([a-z]*\.[a-z]*\.[a-z]*)/) || [];
|
|
476
|
+
const [environment] = account.authority.match(/([a-z]*\.[a-z]*\.[a-z]*)/) || [""];
|
|
477
477
|
return Object.assign(Object.assign({}, account), { localAccountId: account.homeAccountId, environment });
|
|
478
478
|
}
|
|
479
479
|
function msalToPublic(clientId, account) {
|
|
@@ -667,7 +667,7 @@ function mapScopesToResource(scopes) {
|
|
|
667
667
|
* Given a token response, return the expiration timestamp as the number of milliseconds from the Unix epoch.
|
|
668
668
|
* @param body - A parsed response body from the authentication endpoint.
|
|
669
669
|
*/
|
|
670
|
-
function
|
|
670
|
+
function parseExpirationTimestamp(body) {
|
|
671
671
|
if (typeof body.expires_on === "number") {
|
|
672
672
|
return body.expires_on * 1000;
|
|
673
673
|
}
|
|
@@ -743,7 +743,7 @@ class IdentityClient extends coreClient.ServiceClient {
|
|
|
743
743
|
const token = {
|
|
744
744
|
accessToken: {
|
|
745
745
|
token: parsedBody.access_token,
|
|
746
|
-
expiresOnTimestamp:
|
|
746
|
+
expiresOnTimestamp: parseExpirationTimestamp(parsedBody),
|
|
747
747
|
},
|
|
748
748
|
refreshToken: parsedBody.refresh_token,
|
|
749
749
|
};
|
|
@@ -1197,7 +1197,7 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
|
1197
1197
|
* Attempts to retrieve a token from cache.
|
|
1198
1198
|
*/
|
|
1199
1199
|
async getTokenSilent(scopes, options) {
|
|
1200
|
-
var _a, _b;
|
|
1200
|
+
var _a, _b, _c;
|
|
1201
1201
|
await this.getActiveAccount();
|
|
1202
1202
|
if (!this.account) {
|
|
1203
1203
|
throw new AuthenticationRequiredError({
|
|
@@ -1216,7 +1216,14 @@ To work with multiple accounts for the same Client ID and Tenant ID, please prov
|
|
|
1216
1216
|
};
|
|
1217
1217
|
try {
|
|
1218
1218
|
this.logger.info("Attempting to acquire token silently");
|
|
1219
|
-
|
|
1219
|
+
/**
|
|
1220
|
+
* The following code to retrieve all accounts is done as a workaround in an attempt to force the
|
|
1221
|
+
* refresh of the token cache with the token and the account passed in through the
|
|
1222
|
+
* `authenticationRecord` parameter. See issue - https://github.com/Azure/azure-sdk-for-js/issues/24349#issuecomment-1496715651
|
|
1223
|
+
* This workaround serves as a workoaround for silent authentication not happening when authenticationRecord is passed.
|
|
1224
|
+
*/
|
|
1225
|
+
await ((_a = (this.publicApp || this.confidentialApp)) === null || _a === void 0 ? void 0 : _a.getTokenCache().getAllAccounts());
|
|
1226
|
+
const response = (_c = (await ((_b = this.confidentialApp) === null || _b === void 0 ? void 0 : _b.acquireTokenSilent(silentRequest)))) !== null && _c !== void 0 ? _c : (await this.publicApp.acquireTokenSilent(silentRequest));
|
|
1220
1227
|
return this.handleResult(scopes, this.clientId, response || undefined);
|
|
1221
1228
|
}
|
|
1222
1229
|
catch (err) {
|
|
@@ -1963,43 +1970,42 @@ const SupportedWorkloadEnvironmentVariables = [
|
|
|
1963
1970
|
];
|
|
1964
1971
|
const logger$g = credentialLogger(credentialName$3);
|
|
1965
1972
|
/**
|
|
1966
|
-
*
|
|
1967
|
-
*
|
|
1968
|
-
*
|
|
1973
|
+
* Workload Identity authentication is a feature in Azure that allows applications running on virtual machines (VMs)
|
|
1974
|
+
* to access other Azure resources without the need for a service principal or managed identity. With Workload Identity
|
|
1975
|
+
* authentication, applications authenticate themselves using their own identity, rather than using a shared service
|
|
1976
|
+
* principal or managed identity. Under the hood, Workload Identity authentication uses the concept of Service Account
|
|
1977
|
+
* Credentials (SACs), which are automatically created by Azure and stored securely in the VM. By using Workload
|
|
1978
|
+
* Identity authentication, you can avoid the need to manage and rotate service principals or managed identities for
|
|
1979
|
+
* each application on each VM. Additionally, because SACs are created automatically and managed by Azure, you don't
|
|
1980
|
+
* need to worry about storing and securing sensitive credentials themselves.
|
|
1981
|
+
* The WorkloadIdentityCredential supports Azure workload identity authentication on Azure Kubernetes and acquires
|
|
1982
|
+
* a token using the SACs available in the Azure Kubernetes environment.
|
|
1983
|
+
* Refer to <a href="https://learn.microsoft.com/azure/aks/workload-identity-overview">Azure Active Directory
|
|
1984
|
+
* Workload Identity</a> for more information.
|
|
1969
1985
|
*/
|
|
1970
1986
|
class WorkloadIdentityCredential {
|
|
1971
1987
|
/**
|
|
1972
|
-
*
|
|
1973
|
-
*
|
|
1988
|
+
* WorkloadIdentityCredential supports Azure workload identity on Kubernetes.
|
|
1989
|
+
*
|
|
1990
|
+
* @param options - The identity client options to use for authentication.
|
|
1974
1991
|
*/
|
|
1975
1992
|
constructor(options) {
|
|
1976
1993
|
this.azureFederatedTokenFileContent = undefined;
|
|
1977
1994
|
this.cacheDate = undefined;
|
|
1995
|
+
// Logging environment variables for error details
|
|
1996
|
+
const assignedEnv = processEnvVars(SupportedWorkloadEnvironmentVariables).assigned.join(", ");
|
|
1997
|
+
logger$g.info(`Found the following environment variables: ${assignedEnv}`);
|
|
1978
1998
|
const workloadIdentityCredentialOptions = options;
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
}
|
|
1986
|
-
this.federatedTokenFilePath = workloadIdentityCredentialOptions.federatedTokenFilePath;
|
|
1987
|
-
logger$g.info(`Invoking ClientAssertionCredential with tenant ID: ${tenantId}, clientId: ${workloadIdentityCredentialOptions.clientId} and federated token path: [REDACTED]`);
|
|
1988
|
-
this.client = new ClientAssertionCredential(tenantId, workloadIdentityCredentialOptions.clientId, this.readFileContents.bind(this), options);
|
|
1999
|
+
const tenantId = workloadIdentityCredentialOptions.tenantId || process.env.AZURE_TENANT_ID;
|
|
2000
|
+
const clientId = workloadIdentityCredentialOptions.clientId || process.env.AZURE_CLIENT_ID;
|
|
2001
|
+
this.federatedTokenFilePath =
|
|
2002
|
+
workloadIdentityCredentialOptions.tokenFilePath || process.env.AZURE_FEDERATED_TOKEN_FILE;
|
|
2003
|
+
if (tenantId) {
|
|
2004
|
+
checkTenantId(logger$g, tenantId);
|
|
1989
2005
|
}
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
logger$g.info(`Found the following environment variables: ${assigned}`);
|
|
1994
|
-
const tenantId = process.env.AZURE_TENANT_ID, clientId = process.env.AZURE_CLIENT_ID, federatedTokenFilePath = process.env.AZURE_FEDERATED_TOKEN_FILE;
|
|
1995
|
-
this.federatedTokenFilePath = federatedTokenFilePath;
|
|
1996
|
-
if (tenantId) {
|
|
1997
|
-
checkTenantId(logger$g, tenantId);
|
|
1998
|
-
}
|
|
1999
|
-
if (tenantId && clientId && federatedTokenFilePath) {
|
|
2000
|
-
logger$g.info(`Invoking ClientAssertionCredential with the following environment variables tenant ID: ${tenantId}, clientId: ${clientId} and federatedTokenFilePath: [REDACTED]`);
|
|
2001
|
-
this.client = new ClientAssertionCredential(tenantId, clientId, this.readFileContents.bind(this), options);
|
|
2002
|
-
}
|
|
2006
|
+
if (clientId && tenantId && this.federatedTokenFilePath) {
|
|
2007
|
+
logger$g.info(`Invoking ClientAssertionCredential with tenant ID: ${tenantId}, clientId: ${workloadIdentityCredentialOptions.clientId} and federated token path: [REDACTED]`);
|
|
2008
|
+
this.client = new ClientAssertionCredential(tenantId, clientId, this.readFileContents.bind(this), options);
|
|
2003
2009
|
}
|
|
2004
2010
|
}
|
|
2005
2011
|
/**
|
|
@@ -2016,7 +2022,7 @@ class WorkloadIdentityCredential {
|
|
|
2016
2022
|
In DefaultAzureCredential and ManagedIdentityCredential, these can be provided as environment variables -
|
|
2017
2023
|
"AZURE_TENANT_ID",
|
|
2018
2024
|
"AZURE_CLIENT_ID",
|
|
2019
|
-
"AZURE_FEDERATED_TOKEN_FILE"`;
|
|
2025
|
+
"AZURE_FEDERATED_TOKEN_FILE". See the troubleshooting guide for more information: https://aka.ms/azsdk/js/identity/workloadidentitycredential/troubleshoot `;
|
|
2020
2026
|
logger$g.info(errorMessage);
|
|
2021
2027
|
throw new CredentialUnavailableError(errorMessage);
|
|
2022
2028
|
}
|
|
@@ -2068,7 +2074,7 @@ function tokenExchangeMsi() {
|
|
|
2068
2074
|
async getToken(configuration, getTokenOptions = {}) {
|
|
2069
2075
|
const { scopes, clientId } = configuration;
|
|
2070
2076
|
const identityClientTokenCredentialOptions = {};
|
|
2071
|
-
const workloadIdentityCredential = new WorkloadIdentityCredential(Object.assign(Object.assign({ clientId, tenantId: process.env.AZURE_TENANT_ID,
|
|
2077
|
+
const workloadIdentityCredential = new WorkloadIdentityCredential(Object.assign(Object.assign({ clientId, tenantId: process.env.AZURE_TENANT_ID, tokenFilePath: process.env.AZURE_FEDERATED_TOKEN_FILE }, identityClientTokenCredentialOptions), { disableInstanceDiscovery: true }));
|
|
2072
2078
|
const token = await workloadIdentityCredential.getToken(scopes, getTokenOptions);
|
|
2073
2079
|
return token;
|
|
2074
2080
|
},
|
|
@@ -2249,6 +2255,7 @@ class ManagedIdentityCredential {
|
|
|
2249
2255
|
constructor(clientIdOrOptions, options) {
|
|
2250
2256
|
var _a;
|
|
2251
2257
|
this.isEndpointUnavailable = null;
|
|
2258
|
+
this.isAppTokenProviderInitialized = false;
|
|
2252
2259
|
let _options;
|
|
2253
2260
|
if (typeof clientIdOrOptions === "string") {
|
|
2254
2261
|
this.clientId = clientIdOrOptions;
|
|
@@ -2357,27 +2364,32 @@ class ManagedIdentityCredential {
|
|
|
2357
2364
|
scopes: Array.isArray(scopes) ? scopes : [scopes],
|
|
2358
2365
|
claims: options === null || options === void 0 ? void 0 : options.claims,
|
|
2359
2366
|
};
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
|
|
2364
|
-
logger$c.info(`SetAppTokenProvider
|
|
2365
|
-
const
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2367
|
+
// Added a check to see if SetAppTokenProvider was already defined.
|
|
2368
|
+
// Don't redefine it if it's already defined, since it should be static method.
|
|
2369
|
+
if (!this.isAppTokenProviderInitialized) {
|
|
2370
|
+
this.confidentialApp.SetAppTokenProvider(async (appTokenProviderParameters = appTokenParameters) => {
|
|
2371
|
+
logger$c.info(`SetAppTokenProvider invoked with parameters- ${JSON.stringify(appTokenProviderParameters)}`);
|
|
2372
|
+
const resultToken = await this.authenticateManagedIdentity(scopes, Object.assign(Object.assign({}, updatedOptions), appTokenProviderParameters));
|
|
2373
|
+
if (resultToken) {
|
|
2374
|
+
logger$c.info(`SetAppTokenProvider has saved the token in cache`);
|
|
2375
|
+
const expiresInSeconds = (resultToken === null || resultToken === void 0 ? void 0 : resultToken.expiresOnTimestamp)
|
|
2376
|
+
? Math.floor((resultToken.expiresOnTimestamp - Date.now()) / 1000)
|
|
2377
|
+
: 0;
|
|
2378
|
+
return {
|
|
2379
|
+
accessToken: resultToken === null || resultToken === void 0 ? void 0 : resultToken.token,
|
|
2380
|
+
expiresInSeconds,
|
|
2381
|
+
};
|
|
2382
|
+
}
|
|
2383
|
+
else {
|
|
2384
|
+
logger$c.info(`SetAppTokenProvider token has "no_access_token_returned" as the saved token`);
|
|
2385
|
+
return {
|
|
2386
|
+
accessToken: "no_access_token_returned",
|
|
2387
|
+
expiresInSeconds: 0,
|
|
2388
|
+
};
|
|
2389
|
+
}
|
|
2390
|
+
});
|
|
2391
|
+
this.isAppTokenProviderInitialized = true;
|
|
2392
|
+
}
|
|
2381
2393
|
const authenticationResult = await this.confidentialApp.acquireTokenByClientCredential(Object.assign({}, appTokenParameters));
|
|
2382
2394
|
result = this.handleResult(scopes, authenticationResult || undefined);
|
|
2383
2395
|
}
|
|
@@ -2547,7 +2559,7 @@ const cliCredentialInternals = {
|
|
|
2547
2559
|
* @param resource - The resource to use when getting the token
|
|
2548
2560
|
* @internal
|
|
2549
2561
|
*/
|
|
2550
|
-
async getAzureCliAccessToken(resource, tenantId) {
|
|
2562
|
+
async getAzureCliAccessToken(resource, tenantId, timeout) {
|
|
2551
2563
|
let tenantSection = [];
|
|
2552
2564
|
if (tenantId) {
|
|
2553
2565
|
tenantSection = ["--tenant", tenantId];
|
|
@@ -2562,7 +2574,7 @@ const cliCredentialInternals = {
|
|
|
2562
2574
|
"--resource",
|
|
2563
2575
|
resource,
|
|
2564
2576
|
...tenantSection,
|
|
2565
|
-
], { cwd: cliCredentialInternals.getSafeWorkingDir(), shell: true }, (error, stdout, stderr) => {
|
|
2577
|
+
], { cwd: cliCredentialInternals.getSafeWorkingDir(), shell: true, timeout }, (error, stdout, stderr) => {
|
|
2566
2578
|
resolve({ stdout: stdout, stderr: stderr, error });
|
|
2567
2579
|
});
|
|
2568
2580
|
}
|
|
@@ -2591,6 +2603,7 @@ class AzureCliCredential {
|
|
|
2591
2603
|
constructor(options) {
|
|
2592
2604
|
this.tenantId = options === null || options === void 0 ? void 0 : options.tenantId;
|
|
2593
2605
|
this.additionallyAllowedTenantIds = resolveAddionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
|
|
2606
|
+
this.timeout = options === null || options === void 0 ? void 0 : options.processTimeoutInMs;
|
|
2594
2607
|
}
|
|
2595
2608
|
/**
|
|
2596
2609
|
* Authenticates with Azure Active Directory and returns an access token if successful.
|
|
@@ -2609,7 +2622,7 @@ class AzureCliCredential {
|
|
|
2609
2622
|
return tracingClient.withSpan(`${this.constructor.name}.getToken`, options, async () => {
|
|
2610
2623
|
var _a, _b, _c, _d;
|
|
2611
2624
|
try {
|
|
2612
|
-
const obj = await cliCredentialInternals.getAzureCliAccessToken(resource, tenantId);
|
|
2625
|
+
const obj = await cliCredentialInternals.getAzureCliAccessToken(resource, tenantId, this.timeout);
|
|
2613
2626
|
const specificScope = (_a = obj.stderr) === null || _a === void 0 ? void 0 : _a.match("(.*)az login --scope(.*)");
|
|
2614
2627
|
const isLoginError = ((_b = obj.stderr) === null || _b === void 0 ? void 0 : _b.match("(.*)az login(.*)")) && !specificScope;
|
|
2615
2628
|
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"));
|
|
@@ -2702,11 +2715,14 @@ function formatCommand(commandName) {
|
|
|
2702
2715
|
* If anything fails, an error is thrown.
|
|
2703
2716
|
* @internal
|
|
2704
2717
|
*/
|
|
2705
|
-
async function runCommands(commands) {
|
|
2718
|
+
async function runCommands(commands, timeout) {
|
|
2706
2719
|
const results = [];
|
|
2707
2720
|
for (const command of commands) {
|
|
2708
2721
|
const [file, ...parameters] = command;
|
|
2709
|
-
const result = (await processUtils.execFile(file, parameters, {
|
|
2722
|
+
const result = (await processUtils.execFile(file, parameters, {
|
|
2723
|
+
encoding: "utf8",
|
|
2724
|
+
timeout,
|
|
2725
|
+
}));
|
|
2710
2726
|
results.push(result);
|
|
2711
2727
|
}
|
|
2712
2728
|
return results;
|
|
@@ -2761,16 +2777,17 @@ class AzurePowerShellCredential {
|
|
|
2761
2777
|
constructor(options) {
|
|
2762
2778
|
this.tenantId = options === null || options === void 0 ? void 0 : options.tenantId;
|
|
2763
2779
|
this.additionallyAllowedTenantIds = resolveAddionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
|
|
2780
|
+
this.timeout = options === null || options === void 0 ? void 0 : options.processTimeoutInMs;
|
|
2764
2781
|
}
|
|
2765
2782
|
/**
|
|
2766
2783
|
* Gets the access token from Azure PowerShell
|
|
2767
2784
|
* @param resource - The resource to use when getting the token
|
|
2768
2785
|
*/
|
|
2769
|
-
async getAzurePowerShellAccessToken(resource, tenantId) {
|
|
2786
|
+
async getAzurePowerShellAccessToken(resource, tenantId, timeout) {
|
|
2770
2787
|
// Clone the stack to avoid mutating it while iterating
|
|
2771
2788
|
for (const powerShellCommand of [...commandStack]) {
|
|
2772
2789
|
try {
|
|
2773
|
-
await runCommands([[powerShellCommand, "/?"]]);
|
|
2790
|
+
await runCommands([[powerShellCommand, "/?"]], timeout);
|
|
2774
2791
|
}
|
|
2775
2792
|
catch (e) {
|
|
2776
2793
|
// Remove this credential from the original stack so that we don't try it again.
|
|
@@ -2818,7 +2835,7 @@ class AzurePowerShellCredential {
|
|
|
2818
2835
|
logger$a.getToken.info(`Using the scope ${scope}`);
|
|
2819
2836
|
const resource = getScopeResource(scope);
|
|
2820
2837
|
try {
|
|
2821
|
-
const response = await this.getAzurePowerShellAccessToken(resource, tenantId);
|
|
2838
|
+
const response = await this.getAzurePowerShellAccessToken(resource, tenantId, this.timeout);
|
|
2822
2839
|
logger$a.getToken.info(formatSuccess(scopes));
|
|
2823
2840
|
return {
|
|
2824
2841
|
token: response.Token,
|
|
@@ -2884,14 +2901,18 @@ class ChainedTokenCredential {
|
|
|
2884
2901
|
* `TokenCredential` implementation might make.
|
|
2885
2902
|
*/
|
|
2886
2903
|
async getToken(scopes, options = {}) {
|
|
2904
|
+
const { token } = await this.getTokenInternal(scopes, options);
|
|
2905
|
+
return token;
|
|
2906
|
+
}
|
|
2907
|
+
async getTokenInternal(scopes, options = {}) {
|
|
2887
2908
|
let token = null;
|
|
2888
|
-
let
|
|
2909
|
+
let successfulCredential;
|
|
2889
2910
|
const errors = [];
|
|
2890
2911
|
return tracingClient.withSpan("ChainedTokenCredential.getToken", options, async (updatedOptions) => {
|
|
2891
2912
|
for (let i = 0; i < this._sources.length && token === null; i++) {
|
|
2892
2913
|
try {
|
|
2893
2914
|
token = await this._sources[i].getToken(scopes, updatedOptions);
|
|
2894
|
-
|
|
2915
|
+
successfulCredential = this._sources[i];
|
|
2895
2916
|
}
|
|
2896
2917
|
catch (err) {
|
|
2897
2918
|
if (err.name === "CredentialUnavailableError" ||
|
|
@@ -2909,11 +2930,11 @@ class ChainedTokenCredential {
|
|
|
2909
2930
|
logger$9.getToken.info(formatError(scopes, err));
|
|
2910
2931
|
throw err;
|
|
2911
2932
|
}
|
|
2912
|
-
logger$9.getToken.info(`Result for ${
|
|
2933
|
+
logger$9.getToken.info(`Result for ${successfulCredential.constructor.name}: ${formatSuccess(scopes)}`);
|
|
2913
2934
|
if (token === null) {
|
|
2914
2935
|
throw new CredentialUnavailableError("Failed to retrieve a valid token");
|
|
2915
2936
|
}
|
|
2916
|
-
return token;
|
|
2937
|
+
return { token, successfulCredential };
|
|
2917
2938
|
});
|
|
2918
2939
|
}
|
|
2919
2940
|
}
|
|
@@ -3376,7 +3397,7 @@ const developerCliCredentialInternals = {
|
|
|
3376
3397
|
* @param scopes - The scopes to use when getting the token
|
|
3377
3398
|
* @internal
|
|
3378
3399
|
*/
|
|
3379
|
-
async getAzdAccessToken(scopes, tenantId) {
|
|
3400
|
+
async getAzdAccessToken(scopes, tenantId, timeout) {
|
|
3380
3401
|
let tenantSection = [];
|
|
3381
3402
|
if (tenantId) {
|
|
3382
3403
|
tenantSection = ["--tenant-id", tenantId];
|
|
@@ -3390,7 +3411,11 @@ const developerCliCredentialInternals = {
|
|
|
3390
3411
|
"json",
|
|
3391
3412
|
...scopes.reduce((previous, current) => previous.concat("--scope", current), []),
|
|
3392
3413
|
...tenantSection,
|
|
3393
|
-
], {
|
|
3414
|
+
], {
|
|
3415
|
+
cwd: developerCliCredentialInternals.getSafeWorkingDir(),
|
|
3416
|
+
shell: true,
|
|
3417
|
+
timeout,
|
|
3418
|
+
}, (error, stdout, stderr) => {
|
|
3394
3419
|
resolve({ stdout, stderr, error });
|
|
3395
3420
|
});
|
|
3396
3421
|
}
|
|
@@ -3402,23 +3427,43 @@ const developerCliCredentialInternals = {
|
|
|
3402
3427
|
};
|
|
3403
3428
|
const logger$4 = credentialLogger("AzureDeveloperCliCredential");
|
|
3404
3429
|
/**
|
|
3405
|
-
*
|
|
3406
|
-
*
|
|
3407
|
-
*
|
|
3408
|
-
*
|
|
3430
|
+
* Azure Developer CLI is a command-line interface tool that allows developers to create, manage, and deploy
|
|
3431
|
+
* resources in Azure. It's built on top of the Azure CLI and provides additional functionality specific
|
|
3432
|
+
* to Azure developers. It allows users to authenticate as a user and/or a service principal against
|
|
3433
|
+
* <a href="https://learn.microsoft.com/azure/active-directory/fundamentals/">Azure Active Directory (Azure AD)
|
|
3434
|
+
* </a>. The AzureDeveloperCliCredential authenticates in a development environment and acquires a token on behalf of
|
|
3435
|
+
* the logged-in user or service principal in the Azure Developer CLI. It acts as the Azure Developer CLI logged in user or
|
|
3436
|
+
* service principal and executes an Azure CLI command underneath to authenticate the application against
|
|
3437
|
+
* Azure Active Directory.
|
|
3438
|
+
*
|
|
3439
|
+
* <h2> Configure AzureDeveloperCliCredential </h2>
|
|
3440
|
+
*
|
|
3441
|
+
* To use this credential, the developer needs to authenticate locally in Azure Developer CLI using one of the
|
|
3442
|
+
* commands below:
|
|
3443
|
+
*
|
|
3444
|
+
* <ol>
|
|
3445
|
+
* <li>Run "azd auth login" in Azure Developer CLI to authenticate interactively as a user.</li>
|
|
3446
|
+
* <li>Run "azd auth login --client-id clientID --client-secret clientSecret
|
|
3447
|
+
* --tenant-id tenantID" to authenticate as a service principal.</li>
|
|
3448
|
+
* </ol>
|
|
3449
|
+
*
|
|
3450
|
+
* You may need to repeat this process after a certain time period, depending on the refresh token validity in your
|
|
3451
|
+
* organization. Generally, the refresh token validity period is a few weeks to a few months.
|
|
3452
|
+
* AzureDeveloperCliCredential will prompt you to sign in again.
|
|
3409
3453
|
*/
|
|
3410
3454
|
class AzureDeveloperCliCredential {
|
|
3411
3455
|
/**
|
|
3412
3456
|
* Creates an instance of the {@link AzureDeveloperCliCredential}.
|
|
3413
3457
|
*
|
|
3414
3458
|
* To use this credential, ensure that you have already logged
|
|
3415
|
-
* in via the 'azd' tool using the command "azd login" from the commandline.
|
|
3459
|
+
* in via the 'azd' tool using the command "azd auth login" from the commandline.
|
|
3416
3460
|
*
|
|
3417
3461
|
* @param options - Options, to optionally allow multi-tenant requests.
|
|
3418
3462
|
*/
|
|
3419
3463
|
constructor(options) {
|
|
3420
3464
|
this.tenantId = options === null || options === void 0 ? void 0 : options.tenantId;
|
|
3421
3465
|
this.additionallyAllowedTenantIds = resolveAddionallyAllowedTenantIds(options === null || options === void 0 ? void 0 : options.additionallyAllowedTenants);
|
|
3466
|
+
this.timeout = options === null || options === void 0 ? void 0 : options.processTimeoutInMs;
|
|
3422
3467
|
}
|
|
3423
3468
|
/**
|
|
3424
3469
|
* Authenticates with Azure Active Directory and returns an access token if successful.
|
|
@@ -3439,19 +3484,20 @@ class AzureDeveloperCliCredential {
|
|
|
3439
3484
|
}
|
|
3440
3485
|
logger$4.getToken.info(`Using the scopes ${scopes}`);
|
|
3441
3486
|
return tracingClient.withSpan(`${this.constructor.name}.getToken`, options, async () => {
|
|
3442
|
-
var _a, _b, _c;
|
|
3487
|
+
var _a, _b, _c, _d;
|
|
3443
3488
|
try {
|
|
3444
|
-
const obj = await developerCliCredentialInternals.getAzdAccessToken(scopeList, tenantId);
|
|
3445
|
-
const isNotLoggedInError = (_a = obj.stderr) === null || _a === void 0 ? void 0 : _a.match("not logged in, run `azd login` to login")
|
|
3446
|
-
|
|
3447
|
-
|
|
3489
|
+
const obj = await developerCliCredentialInternals.getAzdAccessToken(scopeList, tenantId, this.timeout);
|
|
3490
|
+
const isNotLoggedInError = ((_a = obj.stderr) === null || _a === void 0 ? void 0 : _a.match("not logged in, run `azd login` to login")) ||
|
|
3491
|
+
((_b = obj.stderr) === null || _b === void 0 ? void 0 : _b.match("not logged in, run `azd auth login` to login"));
|
|
3492
|
+
const isNotInstallError = ((_c = obj.stderr) === null || _c === void 0 ? void 0 : _c.match("azd:(.*)not found")) ||
|
|
3493
|
+
((_d = obj.stderr) === null || _d === void 0 ? void 0 : _d.startsWith("'azd' is not recognized"));
|
|
3448
3494
|
if (isNotInstallError || (obj.error && obj.error.code === "ENOENT")) {
|
|
3449
|
-
const error = new CredentialUnavailableError("Azure Developer CLI
|
|
3495
|
+
const error = new CredentialUnavailableError("Azure Developer CLI couldn't be found. To mitigate this issue, see the troubleshooting guidelines at https://aka.ms/azsdk/js/identity/azdevclicredential/troubleshoot.");
|
|
3450
3496
|
logger$4.getToken.info(formatError(scopes, error));
|
|
3451
3497
|
throw error;
|
|
3452
3498
|
}
|
|
3453
3499
|
if (isNotLoggedInError) {
|
|
3454
|
-
const error = new CredentialUnavailableError("Please run 'azd login' from a command prompt to authenticate before using this credential.");
|
|
3500
|
+
const error = new CredentialUnavailableError("Please run 'azd auth login' from a command prompt to authenticate before using this credential. For more information, see the troubleshooting guidelines at https://aka.ms/azsdk/js/identity/azdevclicredential/troubleshoot.");
|
|
3455
3501
|
logger$4.getToken.info(formatError(scopes, error));
|
|
3456
3502
|
throw error;
|
|
3457
3503
|
}
|
|
@@ -3516,13 +3562,56 @@ class DefaultManagedIdentityCredential extends ManagedIdentityCredential {
|
|
|
3516
3562
|
}
|
|
3517
3563
|
}
|
|
3518
3564
|
}
|
|
3565
|
+
/**
|
|
3566
|
+
* A shim around WorkloadIdentityCredential that adapts it to accept
|
|
3567
|
+
* `DefaultAzureCredentialOptions`.
|
|
3568
|
+
*
|
|
3569
|
+
* @internal
|
|
3570
|
+
*/
|
|
3571
|
+
class DefaultWorkloadIdentityCredential extends WorkloadIdentityCredential {
|
|
3572
|
+
// Constructor overload with just the other default options
|
|
3573
|
+
// Last constructor overload with Union of all options not required since the above two constructor overloads have optional properties
|
|
3574
|
+
constructor(options) {
|
|
3575
|
+
var _a, _b, _c;
|
|
3576
|
+
const managedIdentityClientId = (_a = options === null || options === void 0 ? void 0 : options.managedIdentityClientId) !== null && _a !== void 0 ? _a : process.env.AZURE_CLIENT_ID;
|
|
3577
|
+
const workloadIdentityClientId = (_b = options === null || options === void 0 ? void 0 : options.workloadIdentityClientId) !== null && _b !== void 0 ? _b : managedIdentityClientId;
|
|
3578
|
+
const workloadFile = process.env.AZURE_FEDERATED_TOKEN_FILE;
|
|
3579
|
+
const tenantId = (_c = options === null || options === void 0 ? void 0 : options.tenantId) !== null && _c !== void 0 ? _c : process.env.AZURE_TENANT_ID;
|
|
3580
|
+
if (workloadFile && workloadIdentityClientId) {
|
|
3581
|
+
const workloadIdentityCredentialOptions = Object.assign(Object.assign({}, options), { tenantId, clientId: workloadIdentityClientId, tokenFilePath: workloadFile });
|
|
3582
|
+
super(workloadIdentityCredentialOptions);
|
|
3583
|
+
}
|
|
3584
|
+
else if (tenantId) {
|
|
3585
|
+
const workloadIdentityClientTenantOptions = Object.assign(Object.assign({}, options), { tenantId });
|
|
3586
|
+
super(workloadIdentityClientTenantOptions);
|
|
3587
|
+
}
|
|
3588
|
+
else {
|
|
3589
|
+
super(options);
|
|
3590
|
+
}
|
|
3591
|
+
}
|
|
3592
|
+
}
|
|
3593
|
+
class DefaultAzureDeveloperCliCredential extends AzureDeveloperCliCredential {
|
|
3594
|
+
constructor(options) {
|
|
3595
|
+
super(Object.assign({ processTimeoutInMs: options === null || options === void 0 ? void 0 : options.processTimeoutInMs }, options));
|
|
3596
|
+
}
|
|
3597
|
+
}
|
|
3598
|
+
class DefaultAzureCliCredential extends AzureCliCredential {
|
|
3599
|
+
constructor(options) {
|
|
3600
|
+
super(Object.assign({ processTimeoutInMs: options === null || options === void 0 ? void 0 : options.processTimeoutInMs }, options));
|
|
3601
|
+
}
|
|
3602
|
+
}
|
|
3603
|
+
class DefaultAzurePowershellCredential extends AzurePowerShellCredential {
|
|
3604
|
+
constructor(options) {
|
|
3605
|
+
super(Object.assign({ processTimeoutInMs: options === null || options === void 0 ? void 0 : options.processTimeoutInMs }, options));
|
|
3606
|
+
}
|
|
3607
|
+
}
|
|
3519
3608
|
const defaultCredentials = [
|
|
3520
3609
|
EnvironmentCredential,
|
|
3521
|
-
|
|
3610
|
+
DefaultWorkloadIdentityCredential,
|
|
3522
3611
|
DefaultManagedIdentityCredential,
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3612
|
+
DefaultAzureDeveloperCliCredential,
|
|
3613
|
+
DefaultAzureCliCredential,
|
|
3614
|
+
DefaultAzurePowershellCredential,
|
|
3526
3615
|
];
|
|
3527
3616
|
/**
|
|
3528
3617
|
* Provides a default {@link ChainedTokenCredential} configuration that should
|
|
@@ -4073,6 +4162,7 @@ exports.AuthenticationErrorName = AuthenticationErrorName;
|
|
|
4073
4162
|
exports.AuthenticationRequiredError = AuthenticationRequiredError;
|
|
4074
4163
|
exports.AuthorizationCodeCredential = AuthorizationCodeCredential;
|
|
4075
4164
|
exports.AzureCliCredential = AzureCliCredential;
|
|
4165
|
+
exports.AzureDeveloperCliCredential = AzureDeveloperCliCredential;
|
|
4076
4166
|
exports.AzurePowerShellCredential = AzurePowerShellCredential;
|
|
4077
4167
|
exports.ChainedTokenCredential = ChainedTokenCredential;
|
|
4078
4168
|
exports.ClientAssertionCredential = ClientAssertionCredential;
|