You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sdk/identity/azure-identity/README.md
+35-32Lines changed: 35 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,25 +37,25 @@ It's a [known issue](https://github.com/Azure/azure-sdk-for-python/issues/23249)
37
37
38
38
#### Authenticate via the Azure CLI
39
39
40
-
`DefaultAzureCredential` and `AzureCliCredential` can authenticate as the user signed in to the [Azure CLI][azure_cli]. To sign in to the Azure CLI, run `az login`. On a system with a default web browser, the Azure CLI will launch the browser to authenticate a user.
40
+
`DefaultAzureCredential` and `AzureCliCredential` can authenticate as the user signed in to the [Azure CLI][azure_cli]. To sign in to the Azure CLI, run `az login`. On a system with a default web browser, the Azure CLI launches the browser to authenticate a user.
41
41
42
-
When no default browser is available, `az login`will use the device code authentication flow. This flow can also be selected manually by running `az login --use-device-code`.
42
+
When no default browser is available, `az login`uses the device code authentication flow. This flow can also be selected manually by running `az login --use-device-code`.
43
43
44
44
#### Authenticate via the Azure Developer CLI
45
45
46
-
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.
46
+
Developers coding outside of an IDE can also use the [Azure Developer CLI][azure_developer_cli] to authenticate. Applications using `DefaultAzureCredential` or `AzureDeveloperCliCredential` can then use this account to authenticate calls in their application when running locally.
47
47
48
-
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.
48
+
To authenticate with the [Azure Developer CLI][azure_developer_cli], run the command `azd auth login`. For users running on a system with a default web browser, the Azure Developer CLI launches the browser to authenticate the user.
49
49
50
-
For systems without a default web browser, the `azd auth login --use-device-code` command will use the device code authentication flow.
50
+
For systems without a default web browser, the `azd auth login --use-device-code` command uses the device code authentication flow.
51
51
52
52
## Key concepts
53
53
54
54
### Credentials
55
55
56
56
A credential is a class that contains or can obtain the data needed for a service client to authenticate requests. Service clients across the Azure SDK accept a credential instance when they're constructed, and use that credential to authenticate requests.
57
57
58
-
The Azure Identity library focuses on OAuth authentication with Microsoft Entra ID. It offers various credential classes capable of acquiring a Microsoft Entra access token. See the [Credential classes](#credential-classes"Credential classes") section below for a list of this library's credential classes.
58
+
The Azure Identity library focuses on OAuth authentication with Microsoft Entra ID. It offers various credential classes capable of acquiring a Microsoft Entra access token. See the [Credential classes](#credential-classes"Credential classes") section for a list of this library's credential classes.
59
59
60
60
### DefaultAzureCredential
61
61
@@ -67,17 +67,17 @@ The Azure Identity library focuses on OAuth authentication with Microsoft Entra
1.**Environment** - `DefaultAzureCredential`will read account information specified via [environment variables](#environment-variables"environment variables") and use it to authenticate.
71
-
1.**Workload Identity** - If the application is deployed to Azure Kubernetes Service with Managed Identity enabled, `DefaultAzureCredential`will authenticate with it.
72
-
1.**Managed Identity** - If the application is deployed to an Azure host with Managed Identity enabled, `DefaultAzureCredential`will authenticate with it.
73
-
1.**Azure CLI** - If a user has signed in via the Azure CLI `az login` command, `DefaultAzureCredential`will authenticate as that user.
74
-
1.**Azure PowerShell** - If a user has signed in via Azure PowerShell's `Connect-AzAccount` command, `DefaultAzureCredential`will authenticate as that user.
75
-
1.**Azure Developer CLI** - If the developer has authenticated via the Azure Developer CLI `azd auth login` command, the `DefaultAzureCredential`will authenticate with that account.
76
-
1.**Interactive browser** - If enabled, `DefaultAzureCredential`will interactively authenticate a user via the default browser. This credential type is disabled by default.
70
+
1.**Environment** - `DefaultAzureCredential`reads account information specified via [environment variables](#environment-variables"environment variables") and uses it to authenticate.
71
+
1.**Workload Identity** - If the application is deployed to Azure Kubernetes Service with Managed Identity enabled, `DefaultAzureCredential`authenticates with it.
72
+
1.**Managed Identity** - If the application is deployed to an Azure host with Managed Identity enabled, `DefaultAzureCredential`authenticates with it.
73
+
1.**Azure CLI** - If a user signed in via the Azure CLI `az login` command, `DefaultAzureCredential`authenticates as that user.
74
+
1.**Azure PowerShell** - If a user signed in via Azure PowerShell's `Connect-AzAccount` command, `DefaultAzureCredential`authenticates as that user.
75
+
1.**Azure Developer CLI** - If the developer authenticated via the Azure Developer CLI `azd auth login` command, `DefaultAzureCredential`authenticates with that account.
76
+
1.**Interactive browser** - If enabled, `DefaultAzureCredential` interactively authenticates a user via the default browser. This credential type is disabled by default.
77
77
78
78
#### Continuation policy
79
79
80
-
As of version 1.14.0, `DefaultAzureCredential`will attempt to authenticate with all developer credentials until one succeeds, regardless of any errors previous developer credentials experienced. For example, a developer credential may attempt to get a token and fail, so `DefaultAzureCredential` will continue to the next credential in the flow. Deployed service credentials will stop the flow with a thrown exception if they're able to attempt token retrieval, but don't receive one. Prior to version 1.14.0, developer credentials would similarly stop the authentication flow if token retrieval failed, but this is no longer the case.
80
+
As of version 1.14.0, `DefaultAzureCredential`attempts to authenticate with all developer credentials until one succeeds, regardless of any errors previous developer credentials experienced. For example, a developer credential may attempt to get a token and fail, so `DefaultAzureCredential` will continue to the next credential in the flow. Deployed service credentials stop the flow with a thrown exception if they're able to attempt token retrieval, but don't receive one. Prior to version 1.14.0, developer credentials would similarly stop the authentication flow if token retrieval failed, but this is no longer the case.
81
81
82
82
This allows for trying all of the developer credentials on your machine while having predictable deployed behavior.
83
83
@@ -87,15 +87,15 @@ Due to a [known issue](https://github.com/Azure/azure-sdk-for-python/issues/2324
87
87
88
88
## Examples
89
89
90
-
The following examples are provided below:
90
+
The following examples are provided:
91
91
92
92
-[Authenticate with DefaultAzureCredential](#authenticate-with-defaultazurecredential"Authenticate with DefaultAzureCredential")
93
93
-[Define a custom authentication flow with ChainedTokenCredential](#define-a-custom-authentication-flow-with-chainedtokencredential"Define a custom authentication flow with ChainedTokenCredential")
More details on configuring your environment to use the `DefaultAzureCredential` can be found in the class's [reference documentation][default_cred_ref].
98
+
More details on configuring your environment to use `DefaultAzureCredential` can be found in the class's [reference documentation][default_cred_ref].
99
99
100
100
This example demonstrates authenticating the `BlobServiceClient` from the [azure-storage-blob][azure_storage_blob] library using `DefaultAzureCredential`.
@@ -120,7 +120,7 @@ When enabled, `DefaultAzureCredential` falls back to interactively authenticatin
120
120
121
121
#### Specify a user-assigned managed identity for `DefaultAzureCredential`
122
122
123
-
Many Azure hosts allow the assignment of a user-assigned managed identity. To configure `DefaultAzureCredential` to authenticate a user-assigned identity, use the `managed_identity_client_id` keyword argument:
123
+
Many Azure hosts allow the assignment of a user-assigned managed identity. To configure `DefaultAzureCredential` to authenticate a user-assigned managed identity, use the `managed_identity_client_id` keyword argument:
@@ -130,9 +130,9 @@ Alternatively, set the environment variable `AZURE_CLIENT_ID` to the identity's
130
130
131
131
### Define a custom authentication flow with `ChainedTokenCredential`
132
132
133
-
`DefaultAzureCredential` is generally the quickest way to get started developing applications for Azure. For more advanced scenarios, [ChainedTokenCredential][chain_cred_ref] links multiple credential instances to be tried sequentially when authenticating. It will try each chained credential in turn until one provides a token or fails to authenticate due to an error.
133
+
`DefaultAzureCredential` is generally the quickest way to get started developing applications for Azure. For more advanced scenarios, [ChainedTokenCredential][chain_cred_ref] links multiple credential instances to be tried sequentially when authenticating. It tries each credential in turn until one provides a token or fails to authenticate due to an error.
134
134
135
-
The following example demonstrates creating a credential that will first attempt to authenticate using managed identity. The credential will fall back to authenticating via the Azure CLI when a managed identity is unavailable. This example uses the `EventHubProducerClient` from the [azure-eventhub][azure_eventhub] client library.
135
+
The following example demonstrates creating a credential that first attempts to authenticate using managed identity. The credential falls back to authenticating via the Azure CLI when a managed identity is unavailable. This example uses the `EventHubProducerClient` from the [azure-eventhub][azure_eventhub] client library.
136
136
137
137
```python
138
138
from azure.eventhub import EventHubProducerClient
@@ -165,8 +165,7 @@ async with credential:
165
165
...
166
166
```
167
167
168
-
This example demonstrates authenticating the asynchronous `SecretClient` from [azure-keyvault-secrets][azure_keyvault_secrets] with an asynchronous
169
-
credential.
168
+
This example demonstrates authenticating the asynchronous `SecretClient` from [azure-keyvault-secrets][azure_keyvault_secrets] with an asynchronous credential.
170
169
171
170
```python
172
171
from azure.identity.aio import DefaultAzureCredential
[Managed identity authentication](https://learn.microsoft.com/entra/identity/managed-identities-azure-resources/overview) is supported via either the `DefaultAzureCredential` or the`ManagedIdentityCredential` directly for the following Azure services:
180
+
[Managed identity authentication](https://learn.microsoft.com/entra/identity/managed-identities-azure-resources/overview) is supported via either `DefaultAzureCredential` or `ManagedIdentityCredential` directly for the following Azure services:
182
181
183
182
-[Azure App Service and Azure Functions](https://learn.microsoft.com/azure/app-service/overview-managed-identity?tabs=python)
|[`EnvironmentCredential`][environment_cred_ref]| Authenticates a service principal or user via credential information specified in environment variables.
246
250
|[`ManagedIdentityCredential`][managed_id_cred_ref]| Authenticates the managed identity of an Azure resource.
247
251
|[`WorkloadIdentityCredential`][workload_id_cred_ref]| Supports [Microsoft Entra Workload ID](https://learn.microsoft.com/azure/aks/workload-identity-overview) on Kubernetes.
@@ -263,7 +267,7 @@ Not all credentials require this configuration. Credentials that authenticate th
263
267
|[`DeviceCodeCredential`][device_code_cred_ref]| Interactively authenticates a user on devices with limited UI. |[Device code authentication](https://learn.microsoft.com/entra/identity-platform/v2-oauth2-device-code)|
264
268
|[`InteractiveBrowserCredential`][interactive_cred_ref]| Interactively authenticates a user with the default system browser. | [OAuth2 authentication code](https://learn.microsoft.com/entra/identity-platform/v2-oauth2-auth-code-flow)| `InteractiveBrowserCredential` doesn't support GitHub Codespaces. As a workaround, use [`DeviceCodeCredential`][device_code_cred_ref].
265
269
|[`OnBehalfOfCredential`][obo_cred_ref]| Propagates the delegated user identity and permissions through the request chain. |[On-behalf-of authentication](https://learn.microsoft.com/entra/identity-platform/v2-oauth2-on-behalf-of-flow)|
266
-
|[`UsernamePasswordCredential`][userpass_cred_ref]| Authenticates a user with a username and password (doesn't support multi-factor authentication). |[Username + password authentication](https://learn.microsoft.com/entra/identity-platform/v2-oauth-ropc)|
270
+
|[`UsernamePasswordCredential`][userpass_cred_ref]| Authenticates a user with a username and password (doesn't support multifactor authentication). |[Username + password authentication](https://learn.microsoft.com/entra/identity-platform/v2-oauth-ropc)|
267
271
268
272
### Authenticate via development tools
269
273
@@ -295,7 +299,7 @@ variables:
295
299
|`AZURE_TENANT_ID`|ID of the application's Microsoft Entra tenant|X
296
300
|`AZURE_CLIENT_CERTIFICATE_PATH`|path to a PEM or PKCS12 certificate file including private key|X
297
301
|`AZURE_CLIENT_CERTIFICATE_PASSWORD`|password of the certificate file, if any|
298
-
|`AZURE_CLIENT_SEND_CERTIFICATE_CHAIN`|if True, the credential will send the public certificate chain in the x5c header of each token request's JWT. This is required for Subject Name/Issuer (SNI) authentication. Defaults to False. There is a [known limitation](https://github.com/Azure/azure-sdk-for-python/issues/13349) that async SNI authentication is not supported.|
302
+
|`AZURE_CLIENT_SEND_CERTIFICATE_CHAIN`|If `True`, the credential sends the public certificate chain in the x5c header of each token request's JWT. This is required for Subject Name/Issuer (SNI) authentication. Defaults to False. There's a [known limitation](https://github.com/Azure/azure-sdk-for-python/issues/13349) that async SNI authentication isn't supported.|
299
303
300
304
### Username and password
301
305
@@ -305,7 +309,7 @@ variables:
305
309
|`AZURE_USERNAME`|a username (usually an email address)
306
310
|`AZURE_PASSWORD`|that user's password
307
311
308
-
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.
312
+
Configuration is attempted in the preceding order. For example, if values for a client secret and certificate are both present, the client secret is used.
309
313
310
314
## Continuous Access Evaluation
311
315
@@ -318,7 +322,7 @@ Token caching is a feature provided by the Azure Identity library that allows ap
318
322
- Improve resilience and performance.
319
323
- Reduce the number of requests made to Microsoft Entra ID to obtain access tokens.
320
324
321
-
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-python/blob/main/sdk/identity/azure-identity/TOKEN_CACHING.md).
325
+
The Azure Identity library offers both in-memory and persistent disk caching. For more information, see the [token caching documentation](https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/identity/azure-identity/TOKEN_CACHING.md).
322
326
323
327
## Brokered authentication
324
328
@@ -330,8 +334,7 @@ See the [troubleshooting guide][troubleshooting_guide] for details on how to dia
330
334
331
335
### Error handling
332
336
333
-
Credentials raise `CredentialUnavailableError` when they're unable to attempt authentication because they lack required data or state. For example,
334
-
[EnvironmentCredential][environment_cred_ref] will raise this exception when [its configuration](#environment-variables"its configuration") is incomplete.
337
+
Credentials raise `CredentialUnavailableError` when they're unable to attempt authentication because they lack required data or state. For example, [EnvironmentCredential][environment_cred_ref] raises this exception when [its configuration](#environment-variables"its configuration") is incomplete.
335
338
336
339
Credentials raise `azure.core.exceptions.ClientAuthenticationError` when they fail to authenticate. `ClientAuthenticationError` has a `message` attribute, which describes why authentication failed. When raised by `DefaultAzureCredential` or `ChainedTokenCredential`, the message collects error messages from each credential in the chain.
337
340
@@ -341,13 +344,13 @@ For more information on handling specific Microsoft Entra ID errors, see the Mic
341
344
342
345
This library uses the standard [logging](https://docs.python.org/3/library/logging.html) library for logging. Credentials log basic information, including HTTP sessions (URLs, headers, etc.) at INFO level. These log entries don't contain authentication secrets.
343
346
344
-
Detailed DEBUGlevel logging, including request/response bodies and header values, isn't enabled by default. It can be enabled with the `logging_enable` argument. For example:
347
+
Detailed DEBUG-level logging, including request/response bodies and header values, isn't enabled by default. It can be enabled with the `logging_enable` argument. For example:
0 commit comments