Repository navigation
[Identity] Adjust refresh logic - #45496
Merged
Paul Van Eck (pvaneck) merged 7 commits intoMar 12, 2026
Merged
Conversation
- Move _should_refresh from sync/async GetTokenMixin into a shared should_refresh() function in utils.py to eliminate duplication - Ensure expired tokens always trigger refresh, even during retry delay Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Paul Van Eck (pvaneck)
force-pushed
the
identity-should-refresh-mixin
branch
from
March 3, 2026 22:34
5c381dc to
f842b48
Compare
Paul Van Eck (pvaneck)
marked this pull request as ready for review
March 4, 2026 00:52
Paul Van Eck (pvaneck)
requested review from
a team and
Xiang Yan (xiangyan99)
as code owners
March 4, 2026 00:52
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors token refresh decision logic in azure-identity to reduce duplication across sync/async credentials, while fixing edge cases around proactive refresh throttling and ensuring expired tokens always force a refresh.
Changes:
- Centralized refresh decision logic into a shared
should_refresh()helper in_internal/utils.py. - Updated sync/async
GetTokenMixinto use the shared helper and to only record_last_request_timeon failed proactive refresh attempts (avoids cross-token throttling). - Added new unit tests validating
refresh_onbehavior, retry-delay interactions, and “expired token ignores retry delay”.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/identity/azure-identity/azure/identity/_internal/utils.py | Adds shared should_refresh() helper implementing refresh/expiry/retry-delay logic. |
| sdk/identity/azure-identity/azure/identity/_internal/get_token_mixin.py | Uses should_refresh() and updates _last_request_time semantics for proactive refresh failures. |
| sdk/identity/azure-identity/azure/identity/aio/_internal/get_token_mixin.py | Uses should_refresh() and updates _last_request_time semantics for proactive refresh failures (async). |
| sdk/identity/azure-identity/azure/identity/_internal/init.py | Re-exports should_refresh from _internal. |
| sdk/identity/azure-identity/tests/test_get_token_mixin.py | Adds sync tests for refresh_on, retry delay, and expired-token behavior. |
| sdk/identity/azure-identity/tests/test_get_token_mixin_async.py | Adds async equivalents of the new refresh behavior tests. |
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Xiang Yan (xiangyan99)
approved these changes
Mar 12, 2026
Member
Author
|
/check-enforcer override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TokenRefreshStatusenum class and aget_refresh_statusmethod for more granular information on if a token should be refreshed.