Skip to content

Commit adc5f28

Browse files
Update managed identity retry strategy section (#48613)
* Update managed identity retry strategy section * Update code sample * Update code sample * Add headings * Update region name * Add note * Wording tweak * Add clarity * Update docs/azure/sdk/authentication/best-practices.md Co-authored-by: Christopher Scott <[email protected]> --------- Co-authored-by: Christopher Scott <[email protected]>
1 parent 7c0f9b4 commit adc5f28

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

docs/azure/sdk/authentication/best-practices.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Authentication best practices with the Azure Identity library for .NET
33
description: This article describes authentication best practices to follow when using the Azure Identity library for .NET.
44
ms.topic: concept-article
5-
ms.date: 02/14/2025
5+
ms.date: 09/17/2025
66
---
77

88
# Authentication best practices with the Azure Identity library for .NET
@@ -71,13 +71,31 @@ To only call `GetToken` when necessary, observe the `RefreshOn` date and proacti
7171

7272
## Understand the managed identity retry strategy
7373

74-
The Azure Identity library for .NET allows you to authenticate via managed identity with `ManagedIdentityCredential`. The way in which you use `ManagedIdentityCredential` impacts the applied retry strategy. When used via:
74+
The Azure Identity library for .NET allows you to authenticate via managed identity with `ManagedIdentityCredential`. The mode in which you use `ManagedIdentityCredential` impacts the applied retry strategy.
7575

76-
- `DefaultAzureCredential`, no retries are attempted when the initial token acquisition attempt fails or times out after a short duration. This is the least resilient option because it's optimized to "fail fast" for an efficient development inner loop.
77-
- Any other approach, such as `ChainedTokenCredential` or `ManagedIdentityCredential` directly:
78-
- The time interval between retries starts at 0.8 seconds, and a maximum of five retries are attempted, by default. This option is optimized for resilience but introduces potentially unwanted delays in the development inner loop.
79-
- To change any of the default retry settings, use the `Retry` property on `ManagedIdentityCredentialOptions`. For example, retry a maximum of three times, with a starting interval of 0.5 seconds:
76+
### "Fail fast" mode
77+
78+
- **When to use:** For local development scenarios where you want quick feedback
79+
- **How to activate:** Use `DefaultAzureCredential` in one of the following ways:
80+
- Without setting environment variable `AZURE_TOKEN_CREDENTIALS`
81+
- With environment variable `AZURE_TOKEN_CREDENTIALS` set to a string other than `ManagedIdentityCredential`
82+
- **How it works:** No retries are attempted when the initial token acquisition attempt fails or times out after a short duration. This is the least resilient mode because it's optimized to "fail fast" for an efficient development inner loop.
83+
84+
### Resilient mode
85+
86+
- **When to use:** For production scenarios where resilience is important
87+
- **How to activate:** Take one of the following approaches:
88+
- Use `DefaultAzureCredential` with environment variable `AZURE_TOKEN_CREDENTIALS` set to `ManagedIdentityCredential`
89+
90+
> [!IMPORTANT]
91+
> This `DefaultAzureCredential` approach only operates in resilient mode when using `Azure.Identity` package version 1.16.0 or later. In earlier versions, this approach operates in "fail fast" mode.
92+
93+
- Use `ChainedTokenCredential` containing `ManagedIdentityCredential`
94+
- Use `ManagedIdentityCredential` directly
95+
- **How it works:** The time interval between retries starts at 0.8 seconds, and a maximum of five retries are attempted with exponential backoff, by default. This mode is optimized for resilience but introduces potentially unwanted delays in the development inner loop.
96+
97+
To change the default retry settings, use the <xref:Azure.Core.ClientOptions.Retry%2A> property on `DefaultAzureCredentialOptions` or `ManagedIdentityCredentialOptions`. For example, retry a maximum of three times, with a starting interval of 0.5 seconds:
8098

8199
:::code language="csharp" source="../snippets/authentication/best-practices/CCA/Program.cs" id="snippet_retries" highlight="5-9":::
82100

83-
For more information on customizing retry policies, see [Setting a custom retry policy](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/Configuration.md#setting-a-custom-retry-policy).
101+
For more information on customizing retry policies, see [Setting a custom retry policy](https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/Configuration.md#setting-a-custom-retry-policy).

0 commit comments

Comments
 (0)