Honor token type in bearer auth policies#47550
Open
rohitsinghal4u wants to merge 1 commit into
Open
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Azure Core’s sync and async bearer token auth policies to honor AccessTokenInfo.token_type when constructing the Authorization header, enabling scenarios like PoP/MSI token binding while keeping Bearer as the default behavior.
Changes:
- Use
AccessTokenInfo.token_type(when present) instead of always emittingBearerin syncBearerTokenCredentialPolicy. - Apply the same token type behavior in async
AsyncBearerTokenCredentialPolicy. - Add sync/async tests validating header formatting when
token_type="pop".
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| sdk/core/azure-core/azure/core/pipeline/policies/_authentication.py | Uses token’s token_type when setting Authorization header in sync bearer token policy. |
| sdk/core/azure-core/azure/core/pipeline/policies/_authentication_async.py | Uses token’s token_type when setting Authorization header in async bearer token policy. |
| sdk/core/azure-core/tests/test_authentication.py | Adds test validating Authorization header uses AccessTokenInfo.token_type. |
| sdk/core/azure-core/tests/async_tests/test_authentication_async.py | Adds async test validating Authorization header uses AccessTokenInfo.token_type. |
| :param str token_type: The OAuth token type. | ||
| """ | ||
| headers["Authorization"] = "Bearer {}".format(token) | ||
| headers["Authorization"] = "{} {}".format(token_type, token) |
Comment on lines
+78
to
+80
| request.http_request.headers["Authorization"] = "{} {}".format( | ||
| getattr(token, "token_type", "Bearer"), token.token | ||
| ) |
Comment on lines
+95
to
+97
| request.http_request.headers["Authorization"] = "{} {}".format( | ||
| getattr(token, "token_type", "Bearer"), token.token | ||
| ) |
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.
Updates sync and async bearer token auth policies to honor AccessTokenInfo.token_type instead of always emitting Bearer. This is a Core prerequisite for PoP/MSI token binding flows while preserving Bearer as the default.\n\nValidation:\n- python -m pytest tests\test_authentication.py tests\async_tests\test_authentication_async.py -k 'bearer_policy_adds_header' -q