Skip to content

Commit bba6b14

Browse files
authored
Merge pull request #590 from AzureAD/enable-pii
Add enable_pii_log and wire it up with MsalRuntime
2 parents a2410d1 + 3826c6b commit bba6b14

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

msal/application.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ def __init__(
193193
http_cache=None,
194194
instance_discovery=None,
195195
allow_broker=None,
196+
enable_pii_log=None,
196197
):
197198
"""Create an instance of application.
198199
@@ -500,6 +501,13 @@ def __init__(
500501
* AAD and MSA accounts (i.e. Non-ADFS, non-B2C)
501502
502503
New in version 1.20.0.
504+
505+
:param boolean enable_pii_log:
506+
When enabled, logs may include PII (Personal Identifiable Information).
507+
This can be useful in troubleshooting broker behaviors.
508+
The default behavior is False.
509+
510+
New in version 1.24.0.
503511
"""
504512
self.client_id = client_id
505513
self.client_credential = client_credential
@@ -576,6 +584,8 @@ def __init__(
576584
try:
577585
from . import broker # Trigger Broker's initialization
578586
self._enable_broker = True
587+
if enable_pii_log:
588+
broker._enable_pii_log()
579589
except RuntimeError:
580590
logger.exception(
581591
"Broker is unavailable on this platform. "

msal/broker.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,6 @@ def _signout_silently(client_id, account_id, correlation_id=None):
236236
if error:
237237
return _convert_error(error, client_id)
238238

239+
def _enable_pii_log():
240+
pymsalruntime.set_is_pii_enabled(1) # New in PyMsalRuntime 0.13.0
241+

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ broker =
6767
# The broker is defined as optional dependency,
6868
# so that downstream apps can opt in. The opt-in is needed, partially because
6969
# most existing MSAL Python apps do not have the redirect_uri needed by broker.
70-
# MSAL Python uses a subset of API from PyMsalRuntime 0.11.2+,
70+
# MSAL Python uses a subset of API from PyMsalRuntime 0.13.0+,
7171
# but we still bump the lower bound to 0.13.2+ for its important bugfix (https://github.com/AzureAD/microsoft-authentication-library-for-cpp/pull/3244)
7272
pymsalruntime>=0.13.2,<0.14; python_version>='3.6' and platform_system=='Windows'
7373

tests/msaltest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ def main():
161161
option_renderer=lambda a: a["name"],
162162
header="Impersonate this app (or you can type in the client_id of your own app)",
163163
accept_nonempty_string=True)
164+
allow_broker = _input_boolean("Allow broker?")
165+
enable_debug_log = _input_boolean("Enable MSAL Python's DEBUG log?")
166+
enable_pii_log = _input_boolean("Enable PII in broker's log?") if allow_broker and enable_debug_log else False
164167
app = msal.PublicClientApplication(
165168
chosen_app["client_id"] if isinstance(chosen_app, dict) else chosen_app,
166169
authority=_select_options([
@@ -173,9 +176,10 @@ def main():
173176
header="Input authority (Note that MSA-PT apps would NOT use the /common authority)",
174177
accept_nonempty_string=True,
175178
),
176-
allow_broker=_input_boolean("Allow broker? (Azure CLI currently only supports @microsoft.com accounts when enabling broker)"),
179+
allow_broker=allow_broker,
180+
enable_pii_log=enable_pii_log,
177181
)
178-
if _input_boolean("Enable MSAL Python's DEBUG log?"):
182+
if enable_debug_log:
179183
logging.basicConfig(level=logging.DEBUG)
180184
while True:
181185
func = _select_options([

0 commit comments

Comments
 (0)