Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/identity/azure-identity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
### Other Changes

- Bumped minimum dependency on `msal` to `>=1.31.0`.
- Replace instances of `azure.core.pipeline.transport.HttpRequest` with `azure.core.rest.HttpRequest`. ([#44993](https://github.com/Azure/azure-sdk-for-python/pull/44993))

## 1.26.0b1 (2025-11-07)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import functools
import os
from typing import Optional, Dict, Any
from azure.core.pipeline.transport import HttpRequest
from azure.core.rest import HttpRequest

from .._constants import EnvironmentVariables
from .._internal.msal_managed_identity_client import MsalManagedIdentityClient
Expand Down Expand Up @@ -34,6 +34,4 @@ def _get_client_args(**kwargs: Any) -> Optional[Dict]:


def _get_request(url: str, scope: str, identity_config: Dict) -> HttpRequest:
request = HttpRequest("GET", url)
request.format_parameters(dict({"api-version": "2019-08-01", "resource": scope}, **identity_config))
return request
return HttpRequest("GET", url, params=dict({"api-version": "2019-08-01", "resource": scope}, **identity_config))
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import Dict

from azure.core.exceptions import ClientAuthenticationError
from azure.core.pipeline.transport import HttpRequest
from azure.core.rest import HttpRequest
from azure.core.pipeline.policies import HTTPPolicy
from azure.core.pipeline import PipelineRequest, PipelineResponse

Expand All @@ -27,9 +27,7 @@ def _get_request(url: str, scope: str, identity_config: Dict) -> HttpRequest:
"DefaultAzureCredential ensure the AZURE_CLIENT_ID environment variable is not set."
)

request = HttpRequest("GET", url)
request.format_parameters(dict({"api-version": "2020-06-01", "resource": scope}, **identity_config))
return request
return HttpRequest("GET", url, params=dict({"api-version": "2020-06-01", "resource": scope}, **identity_config))


def _get_secret_key(response: PipelineResponse) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
from typing import Optional, Dict

from azure.core.pipeline.transport import HttpRequest
from azure.core.rest import HttpRequest

from .._constants import EnvironmentVariables
from .._internal.msal_managed_identity_client import MsalManagedIdentityClient
Expand Down Expand Up @@ -39,9 +39,7 @@ def _get_client_args(**kwargs) -> Optional[Dict]:


def _get_request(url: str, scope: str, identity_config: Dict) -> HttpRequest:
request = HttpRequest("GET", url)
request.format_parameters(dict({"api-version": "2017-09-01", "resource": scope}, **identity_config))
return request
return HttpRequest("GET", url, params=dict({"api-version": "2017-09-01", "resource": scope}, **identity_config))


def _parse_expires_on(content: Dict) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import os
from typing import Any, Optional, Dict, Mapping

from azure.core.pipeline.transport import HttpRequest
from azure.core.rest import HttpRequest

from .._constants import EnvironmentVariables
from .._internal import within_dac
Expand Down Expand Up @@ -43,5 +43,4 @@ def get_unavailable_message(self, desc: str = "") -> str:


def _get_request(url: str, scope: str, identity_config: Dict) -> HttpRequest:
request = HttpRequest("POST", url, data=dict({"resource": scope}, **identity_config))
return request
return HttpRequest("POST", url, data=dict({"resource": scope}, **identity_config))
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from azure.core.pipeline import PipelineResponse
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError
from azure.core.pipeline.transport import HttpRequest
from azure.core.rest import HttpRequest
from azure.core.credentials import AccessTokenInfo
from azure.core.pipeline.policies import RetryPolicy

Expand Down Expand Up @@ -60,9 +60,7 @@ def _get_request(scope: str, identity_config: Dict) -> HttpRequest:
os.environ.get(EnvironmentVariables.AZURE_POD_IDENTITY_AUTHORITY_HOST, IMDS_AUTHORITY).strip("/")
+ IMDS_TOKEN_PATH
)
request = HttpRequest("GET", url)
request.format_parameters(dict({"api-version": "2018-02-01", "resource": scope}, **identity_config))
return request
return HttpRequest("GET", url, params=dict({"api-version": "2018-02-01", "resource": scope}, **identity_config))


def _check_forbidden_response(ex: HttpResponseError) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from azure.core.credentials import AccessToken, AccessTokenInfo, TokenRequestOptions
from azure.core.exceptions import ClientAuthenticationError
from azure.core.pipeline.transport import HttpRequest
from azure.core.rest import HttpRequest

from .._constants import EnvironmentVariables
from .._internal.msal_managed_identity_client import MsalManagedIdentityClient
Expand Down Expand Up @@ -55,6 +55,6 @@ def _get_client_args(**kwargs: Any) -> Optional[Dict]:


def _get_request(url: str, scope: str, identity_config: Dict) -> HttpRequest:
request = HttpRequest("GET", url)
request.format_parameters(dict({"api-version": "2019-07-01-preview", "resource": scope}, **identity_config))
return request
return HttpRequest(
"GET", url, params=dict({"api-version": "2019-07-01-preview", "resource": scope}, **identity_config)
)
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from azure.core.credentials import AccessTokenInfo
from azure.core.pipeline import Pipeline
from azure.core.pipeline.transport import HttpRequest
from azure.core.rest import HttpRequest
from .aad_client_base import AadClientBase
from .aadclient_certificate import AadClientCertificate
from .pipeline import build_pipeline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.policies import ContentDecodePolicy
from azure.core.pipeline.transport import HttpRequest
from azure.core.rest import HttpRequest
from azure.core.credentials import AccessTokenInfo
from azure.core.exceptions import ClientAuthenticationError
from .utils import get_default_authority, normalize_authority, resolve_tenant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from azure.core.exceptions import ClientAuthenticationError, DecodeError
from azure.core.pipeline.policies import ContentDecodePolicy
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.transport import HttpRequest
from azure.core.rest import HttpRequest
from .. import CredentialUnavailableError
from .._internal import _scopes_to_resource
from .._internal.pipeline import build_pipeline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

from azure.core.exceptions import ClientAuthenticationError
from azure.core.pipeline.policies import ContentDecodePolicy
from azure.core.pipeline.transport import ( # pylint:disable=no-legacy-azure-core-http-response-import
HttpRequest,
HttpResponse,
)
from azure.core.rest import HttpRequest, HttpResponse
from azure.core.pipeline import PipelineResponse
from .pipeline import build_pipeline

Expand All @@ -22,7 +19,7 @@ class MsalResponse:
"""Wraps HttpResponse according to msal.oauth2cli.http.

:param response: The response to wrap.
:type response: ~azure.core.pipeline.transport.HttpResponse
:type response: ~azure.core.rest.HttpResponse
"""

def __init__(self, response: PipelineResponse) -> None:
Expand Down Expand Up @@ -84,19 +81,20 @@ def post(
**kwargs: Any
) -> MsalResponse:
# pylint:disable=unused-argument
request = HttpRequest("POST", url, headers=headers)
if params:
request.format_parameters(params)
request_headers = dict(headers) if headers else {}
content: Optional[bytes] = None
request_data: Optional[Dict[str, str]] = None

if data:
if isinstance(data, dict):
request.headers["Content-Type"] = "application/x-www-form-urlencoded"
request.set_formdata_body(data)
request_headers["Content-Type"] = "application/x-www-form-urlencoded"
request_data = data
elif isinstance(data, str):
body_bytes = data.encode("utf-8")
request.set_bytes_body(body_bytes)
content = data.encode("utf-8")
else:
raise ValueError('expected "data" to be text or a dict')

request = HttpRequest("POST", url, headers=request_headers, params=params, data=request_data, content=content)
response = self._pipeline.run(request, stream=False, retry_on_methods=_POST)
self._store_auth_error(response)
return MsalResponse(response)
Expand All @@ -105,9 +103,7 @@ def get(
self, url: str, params: Optional[Dict[str, str]] = None, headers: Optional[Dict[str, str]] = None, **kwargs: Any
) -> MsalResponse:
# pylint:disable=unused-argument
request = HttpRequest("GET", url, headers=headers)
if params:
request.format_parameters(params)
request = HttpRequest("GET", url, headers=headers, params=params)
response = self._pipeline.run(request, stream=False)
self._store_auth_error(response)
return MsalResponse(response)
Expand All @@ -118,7 +114,7 @@ def get_error_response(self, msal_result: Dict) -> Optional[HttpResponse]:
:param msal_result: The result of an MSAL request.
:type msal_result: dict
:return: The HTTP response associated with the error, if any.
:rtype: ~azure.core.pipeline.transport.HttpResponse or None
:rtype: ~azure.core.rest.HttpResponse or None
"""
error_code, response = getattr(self._local, "error", (None, None))
if response and error_code == msal_result.get("error"):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from azure.core.credentials import AccessTokenInfo
from azure.core.pipeline import AsyncPipeline
from azure.core.pipeline.policies import AsyncHTTPPolicy, SansIOHTTPPolicy
from azure.core.pipeline.transport import HttpRequest
from azure.core.rest import HttpRequest
from ..._internal import AadClientCertificate
from ..._internal import AadClientBase
from ..._internal.pipeline import build_async_pipeline
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from azure.core.credentials import AccessToken
from azure.core.pipeline import AsyncPipeline, Pipeline
from azure.core.pipeline.policies import AsyncBearerTokenCredentialPolicy, BearerTokenCredentialPolicy
from azure.core.pipeline.transport import HttpRequest
from azure.core.rest import HttpRequest


class BearerTokenPolicyTest(PerfStressTest):
Expand Down
3 changes: 2 additions & 1 deletion sdk/identity/azure-identity/tests/test_imds_credential.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
)
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.policies import RetryPolicy
from azure.core.pipeline.transport import HttpRequest, HttpResponse
from azure.core.rest import HttpRequest
from azure.core.pipeline.transport import HttpResponse
Copy link
Member

Choose a reason for hiding this comment

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

Why not
from azure.core.rest import HttpRequest, HttpResponse?

import pytest

from helpers import mock, mock_response, Request, validating_transport, GET_TOKEN_METHODS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
from azure.identity._credentials.imds import PIPELINE_SETTINGS
from azure.core.pipeline import PipelineResponse
from azure.core.pipeline.policies import AsyncRetryPolicy
from azure.core.pipeline.transport import HttpRequest, HttpResponse
from azure.core.rest import HttpRequest
from azure.core.pipeline.transport import HttpResponse
Copy link
Member

Choose a reason for hiding this comment

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

Same, why not
from azure.core.rest import HttpRequest, HttpResponse?

import pytest

from helpers import mock_response, Request, GET_TOKEN_METHODS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time

from azure.core.exceptions import ClientAuthenticationError, ServiceRequestError
from azure.core.pipeline.transport import HttpRequest
from azure.core.rest import HttpRequest
from azure.identity._internal.managed_identity_client import ManagedIdentityClient
import pytest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from unittest.mock import Mock, patch

from azure.core.exceptions import ClientAuthenticationError, ServiceRequestError
from azure.core.pipeline.transport import HttpRequest
from azure.core.rest import HttpRequest
from azure.identity.aio._internal.managed_identity_client import AsyncManagedIdentityClient
import pytest

Expand Down
Loading