Adds a fallback mechanism to AAD scope override.#42731
Merged
aavasthy merged 9 commits intoAzure:mainfrom Sep 5, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a fallback mechanism for AAD scope override in the Azure Cosmos DB client. When no override scope is provided, the client will first attempt authentication with the account scope, and if that fails with the specific error AADSTS500011, it will fallback to the default Cosmos scope https://cosmos.azure.com/.default. The fallback only occurs when using account scope - when an override scope is explicitly provided, no fallback occurs.
Key changes:
- Modified authentication policy classes to support fallback logic with retry mechanism
- Updated client connection initialization to pass both account and override scopes to the policy
- Enhanced test coverage with comprehensive scenarios for scope override and fallback behavior
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
sdk/cosmos/azure-cosmos/azure/cosmos/_auth_policy.py |
Implements fallback logic in sync authentication policy with retry loop for AADSTS500011 errors |
sdk/cosmos/azure-cosmos/azure/cosmos/aio/_auth_policy_async.py |
Implements fallback logic in async authentication policy with retry loop for AADSTS500011 errors |
sdk/cosmos/azure-cosmos/azure/cosmos/_cosmos_client_connection.py |
Updates sync client initialization to pass separate account and override scopes to the policy |
sdk/cosmos/azure-cosmos/azure/cosmos/aio/_cosmos_client_connection_async.py |
Updates async client initialization to pass separate account and override scopes to the policy |
sdk/cosmos/azure-cosmos/tests/test_aad.py |
Adds comprehensive sync test coverage for scope override and fallback scenarios |
sdk/cosmos/azure-cosmos/tests/test_aad_async.py |
Adds comprehensive async test coverage for scope override and fallback scenarios |
xiangyan99
reviewed
Aug 29, 2025
xiangyan99
reviewed
Aug 29, 2025
annatisch
reviewed
Sep 1, 2025
API Change CheckAPIView identified API level changes in this PR and created the following API reviews |
22b491f to
e4e0904
Compare
|
You have several pipelines (over 10) configured to build pull requests in this repository. Specify which pipelines you would like to run by using /azp run [pipelines] command. You can specify multiple pipelines using a comma separated list. |
Member
|
/azp run python - cosmos - ci |
|
Azure Pipelines successfully started running 1 pipeline(s). |
simorenoh
approved these changes
Sep 5, 2025
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.
Description
It's a follow up to this PR #42228, which introduces the ability to override AAD scope value. As part of the current PR:
This is a temporary change we are implementing till this "https://cosmos.azure.com/.default" is accepted as the scope across all environments and clouds.
All SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines