Skip to content

Honor token type in bearer auth policies#47550

Open
rohitsinghal4u wants to merge 1 commit into
mainfrom
rohit/msi-token-binding-core-python
Open

Honor token type in bearer auth policies#47550
rohitsinghal4u wants to merge 1 commit into
mainfrom
rohit/msi-token-binding-core-python

Conversation

@rohitsinghal4u

Copy link
Copy Markdown
Contributor

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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings June 17, 2026 23:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 emitting Bearer in sync BearerTokenCredentialPolicy.
  • 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
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants