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
2 changes: 2 additions & 0 deletions sdk/identity/azure-identity/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

### Bugs Fixed

- Fixed an issue where an unhelpful TypeError was raised during Entra ID token requests that returned certain non-JSON responses. Now, a ClientAuthenticationError is raised with the full response for better troubleshooting. ([#44258](https://github.com/Azure/azure-sdk-for-python/pull/44258))

### Other Changes

## 1.26.0b1 (2025-11-07)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ def _process_response(self, response: PipelineResponse, request_time: int, **kwa
ContentDecodePolicy.CONTEXT_NAME
) or ContentDecodePolicy.deserialize_from_http_generics(response.http_response)

if not content:
raise ClientAuthenticationError(
message="No response content from Microsoft Entra ID", response=response.http_response
)

cache = self._get_cache(**kwargs)
if response.http_request.body.get("grant_type") == "refresh_token":
if content.get("error") == "invalid_grant":
Expand Down
23 changes: 23 additions & 0 deletions sdk/identity/azure-identity/tests/test_aad_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,29 @@ def test_error_reporting():
transport.send.reset_mock()


def test_none_content_handling():
"""Test that _process_response handles None content without raising TypeError"""
http_response = mock_response(status_code=200)
http_response.text = Mock(return_value="")

# Create a mock PipelineResponse with empty context
mock_pipeline_response = Mock()
mock_pipeline_response.context = {}
mock_pipeline_response.http_response = http_response
mock_pipeline_response.http_request = Mock()
mock_pipeline_response.http_request.body = {}

with patch("azure.identity._internal.aad_client_base.ContentDecodePolicy") as mock_policy:
mock_policy.CONTEXT_NAME = "content_decode_policy"
mock_policy.deserialize_from_http_generics = Mock(return_value=None)

transport = Mock()
client = AadClient("tenant id", "client id", transport=transport)

with pytest.raises(ClientAuthenticationError):
client._process_response(mock_pipeline_response, int(1234567890))


@pytest.mark.skip(reason="Adding body to HttpResponseError str. Not an issue bc we don't automatically log errors")
def test_exceptions_do_not_expose_secrets():
secret = "secret"
Expand Down
Loading