Skip to content

Commit 645f4a6

Browse files
authored
[Identity Broker] Propagate enable support logging (#34780)
The msal `enable_pii_log` flag is propagated to the broker runtime in msal, so we should ensure that users can use the `enable_support_logging` flag with the broker credentials. Signed-off-by: Paul Van Eck <[email protected]>
1 parent 1c64ce7 commit 645f4a6

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

sdk/identity/azure-identity-broker/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Features Added
66

77
- `InteractiveBrowserBrokerCredential` now supports a `use_operating_system_account` property to enable the use of the currently logged in operating system account for authentication rather than prompting for a credential.
8+
- Added `enable_support_logging` as a keyword argument to `InteractiveBrowserBrokerCredential`. This allows additional support logging which may contain PII.
89

910
### Breaking Changes
1011

@@ -13,6 +14,7 @@
1314
### Other Changes
1415

1516
- Python 3.7 is no longer supported. Please use Python version 3.8 or later.
17+
- Bumped minimum dependency on `azure-identity` to `1.15.0`.
1618

1719
## 1.0.0 (2023-11-07)
1820

sdk/identity/azure-identity-broker/azure/identity/broker/_browser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ class InteractiveBrowserBrokerCredential(_InteractiveBrowserCredential):
4848
https://login.microsoft.com/ to validate the authority. By setting this to **True**, the validation of the
4949
authority is disabled. As a result, it is crucial to ensure that the configured authority host is valid and
5050
trustworthy.
51+
:keyword bool enable_support_logging: Enables additional support logging in the underlying MSAL library.
52+
This logging potentially contains personally identifiable information and is intended to be used only for
53+
troubleshooting purposes.
5154
:raises ValueError: invalid **redirect_uri**
5255
"""
5356

@@ -135,6 +138,7 @@ def _get_app(self, **kwargs: Any) -> msal.ClientApplication:
135138
http_client=self._client,
136139
instance_discovery=self._instance_discovery,
137140
enable_broker_on_windows=True,
141+
enable_pii_log=self._enable_support_logging,
138142
)
139143

140144
return client_applications_map[tenant_id]

sdk/identity/azure-identity-broker/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
},
6363
python_requires=">=3.8",
6464
install_requires=[
65-
"azure-identity<2.0.0,>=1.14.0",
65+
"azure-identity<2.0.0,>=1.15.0",
6666
"msal[broker]>=1.25,<2",
6767
],
6868
)

sdk/identity/azure-identity-broker/tests/test_broker.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import pytest
66
import sys
77
from unittest.mock import patch, Mock
8+
9+
from azure.core.exceptions import ClientAuthenticationError
810
from azure.identity.broker import InteractiveBrowserBrokerCredential
911

1012

@@ -25,3 +27,31 @@ def test_interactive_browser_broker_cred_signed_in_account():
2527
except Exception: # msal raises TypeError which is expected. We are not testing msal here.
2628
pass
2729
assert mock_signin_silently.called
30+
31+
32+
def test_enable_support_logging_default():
33+
"""The keyword argument for enabling PII in MSAL should be disabled by default."""
34+
35+
cred = InteractiveBrowserBrokerCredential(parent_window_handle="window_handle")
36+
with patch("msal.PublicClientApplication") as mock_client_application:
37+
with patch("msal.PublicClientApplication.acquire_token_interactive"):
38+
with pytest.raises(ClientAuthenticationError):
39+
cred.get_token("scope")
40+
41+
assert mock_client_application.call_count == 1, "credential didn't create an msal application"
42+
_, kwargs = mock_client_application.call_args
43+
assert not kwargs["enable_pii_log"]
44+
45+
46+
def test_enable_support_logging_enabled():
47+
"""The keyword argument for enabling PII in MSAL should be propagated correctly."""
48+
49+
cred = InteractiveBrowserBrokerCredential(parent_window_handle="window_handle", enable_support_logging=True)
50+
with patch("msal.PublicClientApplication") as mock_client_application:
51+
with patch("msal.PublicClientApplication.acquire_token_interactive"):
52+
with pytest.raises(ClientAuthenticationError):
53+
cred.get_token("scope")
54+
55+
assert mock_client_application.call_count == 1, "credential didn't create an msal application"
56+
_, kwargs = mock_client_application.call_args
57+
assert kwargs["enable_pii_log"]

0 commit comments

Comments
 (0)