@azure/identity 3.2.3 → 3.2.4-alpha.20230724.3
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 -9
- package/dist/index.js +35 -26
- package/dist/index.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/managedIdentityCredential/index.js +36 -25
- package/dist-esm/src/credentials/managedIdentityCredential/index.js.map +1 -1
- package/package.json +5 -5
- package/types/identity.d.ts +1 -0
package/README.md
CHANGED
|
@@ -161,10 +161,10 @@ This example demonstrates authenticating the `KeyClient` from the [@azure/keyvau
|
|
|
161
161
|
// If environment configuration is incomplete, it will try managed identity.
|
|
162
162
|
|
|
163
163
|
// Azure Key Vault service to use
|
|
164
|
-
|
|
164
|
+
import { KeyClient } from "@azure/keyvault-keys";
|
|
165
165
|
|
|
166
166
|
// Azure authentication library to access Azure Key Vault
|
|
167
|
-
|
|
167
|
+
import { DefaultAzureCredential } from "@azure/identity";
|
|
168
168
|
|
|
169
169
|
// Azure SDK clients accept the credential as a parameter
|
|
170
170
|
const credential = new DefaultAzureCredential();
|
|
@@ -181,8 +181,8 @@ A relatively common scenario involves authenticating using a user-assigned manag
|
|
|
181
181
|
|
|
182
182
|
While the `DefaultAzureCredential` is generally the quickest way to get started developing applications for Azure, more advanced users may want to customize the credentials considered when authenticating. The `ChainedTokenCredential` enables users to combine multiple credential instances to define a customized chain of credentials. This example demonstrates creating a `ChainedTokenCredential` which will attempt to authenticate using two differently configured instances of `ClientSecretCredential`, to then authenticate the `KeyClient` from the [@azure/keyvault-keys](https://www.npmjs.com/package/@azure/keyvault-keys):
|
|
183
183
|
|
|
184
|
-
```
|
|
185
|
-
|
|
184
|
+
```typescript
|
|
185
|
+
import { ClientSecretCredential, ChainedTokenCredential } from "@azure/identity";
|
|
186
186
|
|
|
187
187
|
// When an access token is requested, the chain will try each
|
|
188
188
|
// credential in order, stopping when one provides a token
|
|
@@ -191,7 +191,7 @@ const secondCredential = new ClientSecretCredential(tenantId, anotherClientId, a
|
|
|
191
191
|
const credentialChain = new ChainedTokenCredential(firstCredential, secondCredential);
|
|
192
192
|
|
|
193
193
|
// The chain can be used anywhere a credential is required
|
|
194
|
-
|
|
194
|
+
import { KeyClient } from "@azure/keyvault-keys";
|
|
195
195
|
const client = new KeyClient(vaultUrl, credentialChain);
|
|
196
196
|
```
|
|
197
197
|
|
|
@@ -213,7 +213,7 @@ For examples of how to use managed identity for authentication, see [the example
|
|
|
213
213
|
|
|
214
214
|
Credentials default to authenticating to the Azure AD endpoint for Azure Public Cloud. To access resources in other clouds, such as Azure Government or a private cloud, configure credentials with the `authorityHost` argument in the constructor. The `AzureAuthorityHosts` interface defines authorities for well-known clouds. For the US Government cloud, you could instantiate a credential this way:
|
|
215
215
|
|
|
216
|
-
```
|
|
216
|
+
```typescript
|
|
217
217
|
import { AzureAuthorityHosts, ClientSecretCredential } from "@azure/identity";
|
|
218
218
|
const credential = new ClientSecretCredential(
|
|
219
219
|
"<YOUR_TENANT_ID>",
|
|
@@ -237,7 +237,7 @@ Not all credentials require this configuration. Credentials that authenticate th
|
|
|
237
237
|
| [`ChainedTokenCredential`](https://learn.microsoft.com/javascript/api/@azure/identity/chainedtokencredential?view=azure-node-latest) | Allows users to define custom authentication flows composing multiple credentials. | [example](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#chaining-credentials) |
|
|
238
238
|
| [`EnvironmentCredential`](https://learn.microsoft.com/javascript/api/@azure/identity/environmentcredential?view=azure-node-latest) | Authenticates a service principal or user via credential information specified in environment variables. | [example](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-a-service-principal-with-environment-credentials) |
|
|
239
239
|
| [`ManagedIdentityCredential`](https://learn.microsoft.com/javascript/api/@azure/identity/managedidentitycredential?view=azure-node-latest) | Authenticates the managed identity of an Azure resource. | [example](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-in-azure-with-managed-identity) |
|
|
240
|
-
|
|
240
|
+
| [`WorkloadIdentityCredential`](https://learn.microsoft.com/javascript/api/@azure/identity/workloadidentitycredential?view=azure-node-latest)| Supports [Azure AD workload identity](https://learn.microsoft.com/azure/aks/workload-identity-overview) on Kubernetes. | |
|
|
241
241
|
|
|
242
242
|
### Authenticate service principals
|
|
243
243
|
|
|
@@ -261,8 +261,8 @@ Not all credentials require this configuration. Credentials that authenticate th
|
|
|
261
261
|
|
|
262
262
|
| Credential | Usage | Example | Reference |
|
|
263
263
|
| ----------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
|
|
264
|
-
| `AzureDeveloperCliCredential` | Authenticate in a development environment with the enabled user or service principal in Azure Developer CLI. | | [Azure Developer CLI Reference](https://learn.microsoft.com/azure/developer/azure-developer-cli/reference) |
|
|
265
264
|
| [`AzureCliCredential`](https://learn.microsoft.com/javascript/api/@azure/identity/azureclicredential?view=azure-node-latest) | Authenticate in a development environment with the Azure CLI. | [example](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-a-user-account-with-azure-cli) | [Azure CLI authentication](https://learn.microsoft.com/cli/azure/authenticate-azure-cli) |
|
|
265
|
+
| [`AzureDeveloperCliCredential`](https://learn.microsoft.com/javascript/api/@azure/identity/azuredeveloperclicredential?view=azure-node-latest) | Authenticate in a development environment with the enabled user or service principal in Azure Developer CLI. | | [Azure Developer CLI Reference](https://learn.microsoft.com/azure/developer/azure-developer-cli/reference) |
|
|
266
266
|
| [`AzurePowerShellCredential`](https://learn.microsoft.com/javascript/api/@azure/identity/azurepowershellcredential?view=azure-node-latest) | Authenticate in a development environment using Azure PowerShell. | [example](https://github.com/Azure/azure-sdk-for-js/blob/main/sdk/identity/identity/samples/AzureIdentityExamples.md#authenticating-a-user-account-with-azure-powershell) | [Azure PowerShell authentication](https://learn.microsoft.com/powershell/azure/authenticate-azureps) |
|
|
267
267
|
| [`VisualStudioCodeCredential`](https://learn.microsoft.com/javascript/api/@azure/identity/visualstudiocodecredential?view=azure-node-latest) | Authenticates as the user signed in to the Visual Studio Code Azure Account extension.| | [VS Code Azure Account extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.azure-account)
|
|
268
268
|
|
|
@@ -299,7 +299,9 @@ Not all credentials require this configuration. Credentials that authenticate th
|
|
|
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
301
|
## Token caching
|
|
302
|
+
|
|
302
303
|
Token caching is a feature provided by the Azure Identity library that allows apps to:
|
|
304
|
+
|
|
303
305
|
- Cache tokens in memory (default) and on disk (opt-in).
|
|
304
306
|
- Improve resilience and performance.
|
|
305
307
|
- Reduce the number of requests made to Azure AD to obtain access tokens.
|
|
@@ -325,7 +327,7 @@ require("dotenv").config({ path: ".env" });
|
|
|
325
327
|
|
|
326
328
|
Alternatively, logging can be enabled at runtime by calling `setLogLevel` from the `@azure/logger` package:
|
|
327
329
|
|
|
328
|
-
```
|
|
330
|
+
```typescript
|
|
329
331
|
import { setLogLevel } from "@azure/logger";
|
|
330
332
|
|
|
331
333
|
setLogLevel("info");
|
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.
|
|
260
|
+
const SDK_VERSION = `3.2.4`;
|
|
261
261
|
/**
|
|
262
262
|
* The default client ID for authentication
|
|
263
263
|
* @internal
|
|
@@ -2282,6 +2282,11 @@ class ManagedIdentityCredential {
|
|
|
2282
2282
|
cloudDiscoveryMetadata: '{"tenant_discovery_endpoint":"https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration","api-version":"1.1","metadata":[{"preferred_network":"login.microsoftonline.com","preferred_cache":"login.windows.net","aliases":["login.microsoftonline.com","login.windows.net","login.microsoft.com","sts.windows.net"]},{"preferred_network":"login.partner.microsoftonline.cn","preferred_cache":"login.partner.microsoftonline.cn","aliases":["login.partner.microsoftonline.cn","login.chinacloudapi.cn"]},{"preferred_network":"login.microsoftonline.de","preferred_cache":"login.microsoftonline.de","aliases":["login.microsoftonline.de"]},{"preferred_network":"login.microsoftonline.us","preferred_cache":"login.microsoftonline.us","aliases":["login.microsoftonline.us","login.usgovcloudapi.net"]},{"preferred_network":"login-us.microsoftonline.com","preferred_cache":"login-us.microsoftonline.com","aliases":["login-us.microsoftonline.com"]}]}',
|
|
2283
2283
|
authorityMetadata: '{"token_endpoint":"https://login.microsoftonline.com/common/oauth2/v2.0/token","token_endpoint_auth_methods_supported":["client_secret_post","private_key_jwt","client_secret_basic"],"jwks_uri":"https://login.microsoftonline.com/common/discovery/v2.0/keys","response_modes_supported":["query","fragment","form_post"],"subject_types_supported":["pairwise"],"id_token_signing_alg_values_supported":["RS256"],"response_types_supported":["code","id_token","code id_token","id_token token"],"scopes_supported":["openid","profile","email","offline_access"],"issuer":"https://login.microsoftonline.com/{tenantid}/v2.0","request_uri_parameter_supported":false,"userinfo_endpoint":"https://graph.microsoft.com/oidc/userinfo","authorization_endpoint":"https://login.microsoftonline.com/common/oauth2/v2.0/authorize","device_authorization_endpoint":"https://login.microsoftonline.com/common/oauth2/v2.0/devicecode","http_logout_supported":true,"frontchannel_logout_supported":true,"end_session_endpoint":"https://login.microsoftonline.com/common/oauth2/v2.0/logout","claims_supported":["sub","iss","cloud_instance_name","cloud_instance_host_name","cloud_graph_host_name","msgraph_host","aud","exp","iat","auth_time","acr","nonce","preferred_username","name","tid","ver","at_hash","c_hash","email"],"kerberos_endpoint":"https://login.microsoftonline.com/common/kerberos","tenant_region_scope":null,"cloud_instance_name":"microsoftonline.com","cloud_graph_host_name":"graph.windows.net","msgraph_host":"graph.microsoft.com","rbac_url":"https://pas.windows.net"}',
|
|
2284
2284
|
},
|
|
2285
|
+
system: {
|
|
2286
|
+
loggerOptions: {
|
|
2287
|
+
logLevel: getMSALLogLevel(logger$o.getLogLevel()),
|
|
2288
|
+
},
|
|
2289
|
+
},
|
|
2285
2290
|
});
|
|
2286
2291
|
}
|
|
2287
2292
|
async cachedAvailableMSI(scopes, getTokenOptions) {
|
|
@@ -2363,31 +2368,7 @@ class ManagedIdentityCredential {
|
|
|
2363
2368
|
claims: options === null || options === void 0 ? void 0 : options.claims,
|
|
2364
2369
|
};
|
|
2365
2370
|
// Added a check to see if SetAppTokenProvider was already defined.
|
|
2366
|
-
|
|
2367
|
-
if (!this.isAppTokenProviderInitialized) {
|
|
2368
|
-
this.confidentialApp.SetAppTokenProvider(async (appTokenProviderParameters = appTokenParameters) => {
|
|
2369
|
-
logger$c.info(`SetAppTokenProvider invoked with parameters- ${JSON.stringify(appTokenProviderParameters)}`);
|
|
2370
|
-
const resultToken = await this.authenticateManagedIdentity(scopes, Object.assign(Object.assign({}, updatedOptions), appTokenProviderParameters));
|
|
2371
|
-
if (resultToken) {
|
|
2372
|
-
logger$c.info(`SetAppTokenProvider has saved the token in cache`);
|
|
2373
|
-
const expiresInSeconds = (resultToken === null || resultToken === void 0 ? void 0 : resultToken.expiresOnTimestamp)
|
|
2374
|
-
? Math.floor((resultToken.expiresOnTimestamp - Date.now()) / 1000)
|
|
2375
|
-
: 0;
|
|
2376
|
-
return {
|
|
2377
|
-
accessToken: resultToken === null || resultToken === void 0 ? void 0 : resultToken.token,
|
|
2378
|
-
expiresInSeconds,
|
|
2379
|
-
};
|
|
2380
|
-
}
|
|
2381
|
-
else {
|
|
2382
|
-
logger$c.info(`SetAppTokenProvider token has "no_access_token_returned" as the saved token`);
|
|
2383
|
-
return {
|
|
2384
|
-
accessToken: "no_access_token_returned",
|
|
2385
|
-
expiresInSeconds: 0,
|
|
2386
|
-
};
|
|
2387
|
-
}
|
|
2388
|
-
});
|
|
2389
|
-
this.isAppTokenProviderInitialized = true;
|
|
2390
|
-
}
|
|
2371
|
+
this.initializeSetAppTokenProvider();
|
|
2391
2372
|
const authenticationResult = await this.confidentialApp.acquireTokenByClientCredential(Object.assign({}, appTokenParameters));
|
|
2392
2373
|
result = this.handleResult(scopes, authenticationResult || undefined);
|
|
2393
2374
|
}
|
|
@@ -2503,6 +2484,34 @@ class ManagedIdentityCredential {
|
|
|
2503
2484
|
throw error(`Response had no "accessToken" property.`);
|
|
2504
2485
|
}
|
|
2505
2486
|
}
|
|
2487
|
+
initializeSetAppTokenProvider() {
|
|
2488
|
+
if (!this.isAppTokenProviderInitialized) {
|
|
2489
|
+
this.confidentialApp.SetAppTokenProvider(async (appTokenProviderParameters) => {
|
|
2490
|
+
logger$c.info(`SetAppTokenProvider invoked with parameters- ${JSON.stringify(appTokenProviderParameters)}`);
|
|
2491
|
+
const getTokenOptions = Object.assign({}, appTokenProviderParameters);
|
|
2492
|
+
logger$c.info(`authenticateManagedIdentity invoked with scopes- ${JSON.stringify(appTokenProviderParameters.scopes)} and getTokenOptions - ${JSON.stringify(getTokenOptions)}`);
|
|
2493
|
+
const resultToken = await this.authenticateManagedIdentity(appTokenProviderParameters.scopes, getTokenOptions);
|
|
2494
|
+
if (resultToken) {
|
|
2495
|
+
logger$c.info(`SetAppTokenProvider will save the token in cache`);
|
|
2496
|
+
const expiresInSeconds = (resultToken === null || resultToken === void 0 ? void 0 : resultToken.expiresOnTimestamp)
|
|
2497
|
+
? Math.floor((resultToken.expiresOnTimestamp - Date.now()) / 1000)
|
|
2498
|
+
: 0;
|
|
2499
|
+
return {
|
|
2500
|
+
accessToken: resultToken === null || resultToken === void 0 ? void 0 : resultToken.token,
|
|
2501
|
+
expiresInSeconds,
|
|
2502
|
+
};
|
|
2503
|
+
}
|
|
2504
|
+
else {
|
|
2505
|
+
logger$c.info(`SetAppTokenProvider token has "no_access_token_returned" as the saved token`);
|
|
2506
|
+
return {
|
|
2507
|
+
accessToken: "no_access_token_returned",
|
|
2508
|
+
expiresInSeconds: 0,
|
|
2509
|
+
};
|
|
2510
|
+
}
|
|
2511
|
+
});
|
|
2512
|
+
this.isAppTokenProviderInitialized = true;
|
|
2513
|
+
}
|
|
2514
|
+
}
|
|
2506
2515
|
}
|
|
2507
2516
|
|
|
2508
2517
|
// Copyright (c) Microsoft Corporation.
|