Skip to content

Commit 88aa723

Browse files
authored
Update Azure Identity lib README (Azure#25931)
**Summary of changes** - Add API ref links for the workload identity and azd credentials - Alphabetize table rows for dev tool credentials - Switch from `require` to `import` in code samples
1 parent 5ae8d9a commit 88aa723

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

sdk/identity/identity/README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,10 @@ This example demonstrates authenticating the `KeyClient` from the [@azure/keyvau
161161
// If environment configuration is incomplete, it will try managed identity.
162162

163163
// Azure Key Vault service to use
164-
const { KeyClient } = require("@azure/keyvault-keys");
164+
import { KeyClient } from "@azure/keyvault-keys";
165165

166166
// Azure authentication library to access Azure Key Vault
167-
const { DefaultAzureCredential } = require("@azure/identity");
167+
import { DefaultAzureCredential } from "@azure/identity";
168168

169169
// Azure SDK clients accept the credential as a parameter
170170
const credential = new DefaultAzureCredential();
@@ -181,8 +181,8 @@ A relatively common scenario involves authenticating using a user-assigned manag
181181

182182
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):
183183

184-
```javascript
185-
const { ClientSecretCredential, ChainedTokenCredential } = require("@azure/identity");
184+
```typescript
185+
import { ClientSecretCredential, ChainedTokenCredential } from "@azure/identity";
186186

187187
// When an access token is requested, the chain will try each
188188
// credential in order, stopping when one provides a token
@@ -191,7 +191,7 @@ const secondCredential = new ClientSecretCredential(tenantId, anotherClientId, a
191191
const credentialChain = new ChainedTokenCredential(firstCredential, secondCredential);
192192

193193
// The chain can be used anywhere a credential is required
194-
const { KeyClient } = require("@azure/keyvault-keys");
194+
import { KeyClient } from "@azure/keyvault-keys";
195195
const client = new KeyClient(vaultUrl, credentialChain);
196196
```
197197

@@ -213,7 +213,7 @@ For examples of how to use managed identity for authentication, see [the example
213213

214214
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:
215215

216-
```ts
216+
```typescript
217217
import { AzureAuthorityHosts, ClientSecretCredential } from "@azure/identity";
218218
const credential = new ClientSecretCredential(
219219
"<YOUR_TENANT_ID>",
@@ -237,7 +237,7 @@ Not all credentials require this configuration. Credentials that authenticate th
237237
| [`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) |
238238
| [`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) |
239239
| [`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-
|`WorkloadIdentityCredential`| Supports [Azure AD workload identity](https://learn.microsoft.com/azure/aks/workload-identity-overview) on Kubernetes. | |
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. | |
241241

242242
### Authenticate service principals
243243

@@ -261,8 +261,8 @@ Not all credentials require this configuration. Credentials that authenticate th
261261

262262
| Credential | Usage | Example | Reference |
263263
| ----------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
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) |
265264
| [`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) |
266266
| [`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) |
267267
| [`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)
268268

@@ -299,7 +299,9 @@ Not all credentials require this configuration. Credentials that authenticate th
299299
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.
300300

301301
## Token caching
302+
302303
Token caching is a feature provided by the Azure Identity library that allows apps to:
304+
303305
- Cache tokens in memory (default) and on disk (opt-in).
304306
- Improve resilience and performance.
305307
- Reduce the number of requests made to Azure AD to obtain access tokens.
@@ -325,7 +327,7 @@ require("dotenv").config({ path: ".env" });
325327

326328
Alternatively, logging can be enabled at runtime by calling `setLogLevel` from the `@azure/logger` package:
327329

328-
```javascript
330+
```typescript
329331
import { setLogLevel } from "@azure/logger";
330332

331333
setLogLevel("info");

0 commit comments

Comments
 (0)