Skip to content

Commit 0fc263f

Browse files
authored
Drive awareness of credential chains doc (#37549)
* Drive awareness of credential chains doc * Fix pylint errors * Fix code formatting * React to feedback
1 parent 584bd18 commit 0fc263f

File tree

5 files changed

+13
-34
lines changed

5 files changed

+13
-34
lines changed

sdk/identity/azure-identity/README.md

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,7 @@ The Azure Identity library focuses on OAuth authentication with Microsoft Entra
5959

6060
### DefaultAzureCredential
6161

62-
`DefaultAzureCredential` is appropriate for most applications that will run in Azure because it combines common production credentials with development credentials. `DefaultAzureCredential` attempts to authenticate via the following mechanisms, in this order, stopping when one succeeds:
63-
64-
>Note: `DefaultAzureCredential` is intended to simplify getting started with the library by handling common
65-
>scenarios with reasonable default behaviors. Developers who want more control or whose scenario
66-
>isn't served by the default settings should use other credential types.
67-
68-
![DefaultAzureCredential authentication flow](https://raw.githubusercontent.com/Azure/azure-sdk-for-python/main/sdk/identity/azure-identity/images/mermaidjs/DefaultAzureCredentialAuthFlow.svg)
69-
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.
62+
`DefaultAzureCredential` simplifies authentication while developing apps that deploy to Azure by combining credentials used in Azure hosting environments with credentials used in local development. For more information, see [DefaultAzureCredential overview][dac_overview].
7763

7864
#### Continuation policy
7965

@@ -118,7 +104,7 @@ DefaultAzureCredential(exclude_interactive_browser_credential=False)
118104

119105
When enabled, `DefaultAzureCredential` falls back to interactively authenticating via the system's default web browser when no other credential is available.
120106

121-
#### Specify a user-assigned managed identity for `DefaultAzureCredential`
107+
#### Specify a user-assigned managed identity with `DefaultAzureCredential`
122108

123109
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:
124110

@@ -130,20 +116,7 @@ Alternatively, set the environment variable `AZURE_CLIENT_ID` to the identity's
130116

131117
### Define a custom authentication flow with `ChainedTokenCredential`
132118

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-
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-
137-
```python
138-
from azure.eventhub import EventHubProducerClient
139-
from azure.identity import AzureCliCredential, ChainedTokenCredential, ManagedIdentityCredential
140-
141-
managed_identity = ManagedIdentityCredential()
142-
azure_cli = AzureCliCredential()
143-
credential_chain = ChainedTokenCredential(managed_identity, azure_cli)
144-
145-
client = EventHubProducerClient(namespace, eventhub_name, credential_chain)
146-
```
119+
While `DefaultAzureCredential` is generally the quickest way to authenticate apps for Azure, you can create a customized chain of credentials to be considered. `ChainedTokenCredential` enables users to combine multiple credential instances to define a customized chain of credentials. For more information, see [ChainedTokenCredential overview][ctc_overview].
147120

148121
### Async credentials
149122

@@ -395,6 +368,8 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
395368
[cli_cred_ref]: https://aka.ms/azsdk/python/identity/azclicredential
396369
[client_assertion_cred_ref]: https://aka.ms/azsdk/python/identity/clientassertioncredential
397370
[client_secret_cred_ref]: https://aka.ms/azsdk/python/identity/clientsecretcredential
371+
[ctc_overview]: https://aka.ms/azsdk/python/identity/credential-chains#chainedtokencredential-overview
372+
[dac_overview]: https://aka.ms/azsdk/python/identity/credential-chains#defaultazurecredential-overview
398373
[default_cred_ref]: https://aka.ms/azsdk/python/identity/defaultazurecredential
399374
[device_code_cred_ref]: https://aka.ms/azsdk/python/identity/devicecodecredential
400375
[environment_cred_ref]: https://aka.ms/azsdk/python/identity/environmentcredential

sdk/identity/azure-identity/azure/identity/_credentials/chained.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class ChainedTokenCredential:
3737
"""A sequence of credentials that is itself a credential.
3838
3939
Its :func:`get_token` method calls ``get_token`` on each credential in the sequence, in order, returning the first
40-
valid token received.
40+
valid token received. For more information, see
41+
https://aka.ms/azsdk/python/identity/credential-chains#chainedtokencredential-overview.
4142
4243
:param credentials: credential instances to form the chain
4344
:type credentials: ~azure.core.credentials.TokenCredential

sdk/identity/azure-identity/azure/identity/_credentials/default.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424

2525

2626
class DefaultAzureCredential(ChainedTokenCredential):
27-
"""A default credential capable of handling most Azure SDK authentication scenarios.
27+
"""A credential capable of handling most Azure SDK authentication scenarios. See
28+
https://aka.ms/azsdk/python/identity/credential-chains#usage-guidance-for-defaultazurecredential.
2829
2930
The identity it uses depends on the environment. When an access token is needed, it requests one using these
3031
identities in turn, stopping when one provides a token:

sdk/identity/azure-identity/azure/identity/aio/_credentials/chained.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class ChainedTokenCredential(AsyncContextManager):
2121
"""A sequence of credentials that is itself a credential.
2222
2323
Its :func:`get_token` method calls ``get_token`` on each credential in the sequence, in order, returning the first
24-
valid token received.
24+
valid token received. For more information, see
25+
https://aka.ms/azsdk/python/identity/credential-chains#chainedtokencredential-overview.
2526
2627
:param credentials: credential instances to form the chain
2728
:type credentials: ~azure.core.credentials.AsyncTokenCredential

sdk/identity/azure-identity/azure/identity/aio/_credentials/default.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626

2727
class DefaultAzureCredential(ChainedTokenCredential):
28-
"""A default credential capable of handling most Azure SDK authentication scenarios.
28+
"""A credential capable of handling most Azure SDK authentication scenarios. See
29+
https://aka.ms/azsdk/python/identity/credential-chains#usage-guidance-for-defaultazurecredential.
2930
3031
The identity it uses depends on the environment. When an access token is needed, it requests one using these
3132
identities in turn, stopping when one provides a token:

0 commit comments

Comments
 (0)