Skip to content

Commit 935d4cc

Browse files
authored
[Identity] Add support logging flag (#32135)
Signed-off-by: Paul Van Eck <[email protected]>
1 parent b8dec12 commit 935d4cc

File tree

7 files changed

+40
-1
lines changed

7 files changed

+40
-1
lines changed

sdk/identity/azure-identity/CHANGELOG.md

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

55
### Features Added
66

7+
- Added `enable_support_logging` as a keyword argument to credentials using MSAL's `PublicClientApplication`. This allows additional support logging which may contain PII. ([#32135](https://github.com/Azure/azure-sdk-for-python/pull/32135))
8+
79
### Breaking Changes
810

911
### Bugs Fixed

sdk/identity/azure-identity/azure/identity/_credentials/browser.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class InteractiveBrowserCredential(InteractiveCredential):
5050
https://login.microsoft.com/ to validate the authority. By setting this to **True**, the validation of the
5151
authority is disabled. As a result, it is crucial to ensure that the configured authority host is valid and
5252
trustworthy.
53+
:keyword bool enable_support_logging: Enables additional support logging in the underlying MSAL library.
54+
This logging potentially contains personally identifiable information and is intended to be used only for
55+
troubleshooting purposes.
5356
:raises ValueError: invalid **redirect_uri**
5457
5558
.. admonition:: Example:

sdk/identity/azure-identity/azure/identity/_credentials/device_code.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ class DeviceCodeCredential(InteractiveCredential):
5454
https://login.microsoft.com/ to validate the authority. By setting this to **True**, the validation of the
5555
authority is disabled. As a result, it is crucial to ensure that the configured authority host is valid and
5656
trustworthy.
57+
:keyword bool enable_support_logging: Enables additional support logging in the underlying MSAL library.
58+
This logging potentially contains personally identifiable information and is intended to be used only for
59+
troubleshooting purposes.
5760
5861
.. admonition:: Example:
5962

sdk/identity/azure-identity/azure/identity/_credentials/user_password.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class UsernamePasswordCredential(InteractiveCredential):
4444
:keyword List[str] additionally_allowed_tenants: Specifies tenants in addition to the specified "tenant_id"
4545
for which the credential may acquire tokens. Add the wildcard value "*" to allow the credential to
4646
acquire tokens for any tenant the application can access.
47+
:keyword bool enable_support_logging: Enables additional support logging in the underlying MSAL library.
48+
This logging potentially contains personally identifiable information and is intended to be used only for
49+
troubleshooting purposes.
4750
4851
.. admonition:: Example:
4952

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(
3333
authority: Optional[str] = None,
3434
disable_instance_discovery: Optional[bool] = None,
3535
tenant_id: Optional[str] = None,
36+
enable_support_logging: Optional[bool] = None,
3637
**kwargs
3738
) -> None:
3839
self._instance_discovery = None if disable_instance_discovery is None else not disable_instance_discovery
@@ -48,6 +49,7 @@ def __init__(
4849
self._allow_broker = allow_broker
4950
self._parent_window_handle = parent_window_handle
5051
self._enable_msa_passthrough = enable_msa_passthrough
52+
self._enable_support_logging = enable_support_logging
5153
self._additionally_allowed_tenants = additionally_allowed_tenants or []
5254

5355
self._client_applications: Dict[str, msal.ClientApplication] = {}
@@ -113,6 +115,7 @@ def _get_app(self, **kwargs: Any) -> msal.ClientApplication:
113115
http_client=self._client,
114116
instance_discovery=self._instance_discovery,
115117
allow_broker=self._allow_broker,
118+
enable_pii_log=self._enable_support_logging,
116119
)
117120

118121
return client_applications_map[tenant_id]

sdk/identity/azure-identity/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
install_requires=[
6262
"azure-core<2.0.0,>=1.11.0",
6363
"cryptography>=2.5",
64-
"msal<2.0.0,>=1.20.0",
64+
"msal<2.0.0,>=1.24.0",
6565
"msal-extensions<2.0.0,>=0.3.0",
6666
],
6767
)

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,31 @@ def validate_app_parameters(authority, client_id, **_):
7777
assert mock_client_application.call_count == 1, "credential didn't create an msal application"
7878

7979

80+
def test_enable_support_logging():
81+
"""The keyword argument for enabling PII in MSAL should be passed."""
82+
83+
record = AuthenticationRecord("tenant-id", "client-id", "localhost", "object.tenant", "username")
84+
85+
def validate_app_parameters(authority, client_id, **_):
86+
# the 'authority' argument to msal.ClientApplication should be a URL of the form https://authority/tenant
87+
assert authority == "https://{}/{}".format(record.authority, record.tenant_id)
88+
assert client_id == record.client_id
89+
return Mock(get_accounts=Mock(return_value=[]))
90+
91+
mock_client_application = Mock(wraps=validate_app_parameters)
92+
93+
credential = MockCredential(
94+
authentication_record=record, disable_automatic_authentication=True, enable_support_logging=True
95+
)
96+
with pytest.raises(AuthenticationRequiredError):
97+
with patch("msal.PublicClientApplication", mock_client_application):
98+
credential.get_token("scope")
99+
100+
assert mock_client_application.call_count == 1, "credential didn't create an msal application"
101+
_, kwargs = mock_client_application.call_args
102+
assert kwargs["enable_pii_log"]
103+
104+
80105
def test_tenant_argument_overrides_record():
81106
"""The 'tenant_ic' keyword argument should override a given record's value"""
82107

0 commit comments

Comments
 (0)