-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Add default impl to handle token challenges #37652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a245cee
Add default impl to handle token challenges
xiangyan99 c53a91b
update version
xiangyan99 fffee09
update
xiangyan99 fa65427
update
xiangyan99 6b12559
update
xiangyan99 bbfe516
update
xiangyan99 70eb72e
Update sdk/core/azure-core/azure/core/pipeline/policies/_utils.py
xiangyan99 3899b13
Update sdk/core/azure-core/azure/core/pipeline/policies/_utils.py
xiangyan99 70dd0d1
update
xiangyan99 4dbc840
Update sdk/core/azure-core/tests/test_utils.py
xiangyan99 dca906e
Update sdk/core/azure-core/azure/core/pipeline/policies/_utils.py
xiangyan99 ce6e329
update
xiangyan99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,7 @@ | |
| import pytest | ||
| from azure.core.utils import case_insensitive_dict | ||
| from azure.core.utils._utils import get_running_async_lock | ||
| from azure.core.pipeline.policies._utils import parse_retry_after | ||
| from azure.core.pipeline.policies._utils import parse_retry_after, get_challenge_parameter | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
|
|
@@ -146,3 +146,58 @@ def test_parse_retry_after(): | |
| assert ret == 0 | ||
| ret = parse_retry_after("0.9") | ||
| assert ret == 0.9 | ||
|
|
||
|
|
||
| def test_get_challenge_parameter(): | ||
| headers = { | ||
| "WWW-Authenticate": 'Bearer authorization_uri="https://login.microsoftonline.com/tenant-id", resource="https://vault.azure.net"' | ||
| } | ||
| assert ( | ||
| get_challenge_parameter(headers, "Bearer", "authorization_uri") == "https://login.microsoftonline.com/tenant-id" | ||
| ) | ||
| assert get_challenge_parameter(headers, "Bearer", "resource") == "https://vault.azure.net" | ||
| assert get_challenge_parameter(headers, "Bearer", "foo") is None | ||
|
|
||
| headers = { | ||
| "WWW-Authenticate": 'Bearer realm="", authorization_uri="https://login.microsoftonline.com/common/oauth2/authorize", error="insufficient_claims", claims="eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwidmFsdWUiOiIxNzI2MDc3NTk1In0sInhtc19jYWVlcnJvciI6eyJ2YWx1ZSI6IjEwMDEyIn19fQ=="' | ||
| } | ||
| assert ( | ||
| get_challenge_parameter(headers, "Bearer", "authorization_uri") | ||
| == "https://login.microsoftonline.com/common/oauth2/authorize" | ||
| ) | ||
| assert get_challenge_parameter(headers, "Bearer", "error") == "insufficient_claims" | ||
| assert ( | ||
| get_challenge_parameter(headers, "Bearer", "claims") | ||
| == "eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwidmFsdWUiOiIxNzI2MDc3NTk1In0sInhtc19jYWVlcnJvciI6eyJ2YWx1ZSI6IjEwMDEyIn19fQ==" | ||
| ) | ||
pvaneck marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def test_get_challenge_parameter_not_found(): | ||
| headers = { | ||
| "WWW-Authenticate": 'Pop authorization_uri="https://login.microsoftonline.com/tenant-id", resource="https://vault.azure.net"' | ||
| } | ||
| assert get_challenge_parameter(headers, "Bearer", "resource") is None | ||
|
|
||
|
|
||
| def test_get_multi_challenge_parameter(): | ||
| headers = { | ||
| "WWW-Authenticate": 'Bearer authorization_uri="https://login.microsoftonline.com/tenant-id", resource="https://vault.azure.net" Bearer authorization_uri="https://login.microsoftonline.com/tenant-id", resource="https://vault.azure.net"' | ||
| } | ||
| assert ( | ||
| get_challenge_parameter(headers, "Bearer", "authorization_uri") == "https://login.microsoftonline.com/tenant-id" | ||
| ) | ||
| assert get_challenge_parameter(headers, "Bearer", "resource") == "https://vault.azure.net" | ||
| assert get_challenge_parameter(headers, "Bearer", "foo") is None | ||
|
|
||
| headers = { | ||
| "WWW-Authenticate": 'Digest realm="[email protected]", qop="auth,auth-int", nonce="123456abcdefg", opaque="123456", Bearer realm="", authorization_uri="https://login.microsoftonline.com/common/oauth2/authorize", error="insufficient_claims", claims="eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwidmFsdWUiOiIxNzI2MDc3NTk1In0sInhtc19jYWVlcnJvciI6eyJ2YWx1ZSI6IjEwMDEyIn19fQ=="' | ||
| } | ||
| assert ( | ||
| get_challenge_parameter(headers, "Bearer", "authorization_uri") | ||
| == "https://login.microsoftonline.com/common/oauth2/authorize" | ||
| ) | ||
| assert get_challenge_parameter(headers, "Bearer", "error") == "insufficient_claims" | ||
| assert ( | ||
| get_challenge_parameter(headers, "Bearer", "claims") | ||
| == "eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwidmFsdWUiOiIxNzI2MDc3NTk1In0sInhtc19jYWVlcnJvciI6eyJ2YWx1ZSI6IjEwMDEyIn19fQ==" | ||
| ) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.