Skip to content

Commit 6decb4e

Browse files
committed
[Identity] Fix TypeError in certain Entra responses
Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
1 parent 2470205 commit 6decb4e

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

sdk/identity/azure-identity/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
### Bugs Fixed
1414

15+
- 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))
16+
1517
### Other Changes
1618

1719
## 1.26.0b1 (2025-11-07)

sdk/identity/azure-identity/azure/identity/_internal/aad_client_base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ def _process_response(self, response: PipelineResponse, request_time: int, **kwa
139139
ContentDecodePolicy.CONTEXT_NAME
140140
) or ContentDecodePolicy.deserialize_from_http_generics(response.http_response)
141141

142+
if not content:
143+
raise ClientAuthenticationError(
144+
message="No response content from Microsoft Entra ID", response=response.http_response
145+
)
146+
142147
cache = self._get_cache(**kwargs)
143148
if response.http_request.body.get("grant_type") == "refresh_token":
144149
if content.get("error") == "invalid_grant":

sdk/identity/azure-identity/tests/test_aad_client.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,29 @@ def test_error_reporting():
5151
transport.send.reset_mock()
5252

5353

54+
def test_none_content_handling():
55+
"""Test that _process_response handles None content without raising TypeError"""
56+
http_response = mock_response(status_code=200)
57+
http_response.text = Mock(return_value="")
58+
59+
# Create a mock PipelineResponse with empty context
60+
mock_pipeline_response = Mock()
61+
mock_pipeline_response.context = {}
62+
mock_pipeline_response.http_response = http_response
63+
mock_pipeline_response.http_request = Mock()
64+
mock_pipeline_response.http_request.body = {}
65+
66+
with patch("azure.identity._internal.aad_client_base.ContentDecodePolicy") as mock_policy:
67+
mock_policy.CONTEXT_NAME = "content_decode_policy"
68+
mock_policy.deserialize_from_http_generics = Mock(return_value=None)
69+
70+
transport = Mock()
71+
client = AadClient("tenant id", "client id", transport=transport)
72+
73+
with pytest.raises(ClientAuthenticationError):
74+
client._process_response(mock_pipeline_response, int(1234567890))
75+
76+
5477
@pytest.mark.skip(reason="Adding body to HttpResponseError str. Not an issue bc we don't automatically log errors")
5578
def test_exceptions_do_not_expose_secrets():
5679
secret = "secret"

0 commit comments

Comments
 (0)