Skip to content

Commit fea7ea9

Browse files
committed
Surface msal telemetry as a long opaque string
Remove wam_telemetry, for now
1 parent 45a0aee commit fea7ea9

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

msal/application.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ def _pii_less_home_account_id(home_account_id):
7373

7474
def _clean_up(result):
7575
if isinstance(result, dict):
76+
if "_msalruntime_telemetry" in result or "_msal_python_telemetry" in result:
77+
result["msal_telemetry"] = json.dumps({ # Telemetry as an opaque string
78+
"msalruntime_telemetry": result.get("_msalruntime_telemetry"),
79+
"msal_python_telemetry": result.get("_msal_python_telemetry"),
80+
}, separators=(",", ":"))
7681
return {
7782
k: result[k] for k in result
7883
if k != "refresh_in" # MSAL handled refresh_in, customers need not
@@ -966,7 +971,7 @@ def authorize(): # A controller in a web app
966971
self._validate_ssh_cert_input_data(kwargs.get("data", {}))
967972
telemetry_context = self._build_telemetry_context(
968973
self.ACQUIRE_TOKEN_BY_AUTHORIZATION_CODE_ID)
969-
response =_clean_up(self.client.obtain_token_by_auth_code_flow(
974+
response = _clean_up(self.client.obtain_token_by_auth_code_flow(
970975
auth_code_flow,
971976
auth_response,
972977
scope=self._decorate_scope(scopes) if scopes else None,

msal/broker.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
except (ImportError, AttributeError): # AttributeError happens when a prior pymsalruntime uninstallation somehow leaved an empty folder behind
2424
# PyMsalRuntime currently supports these Windows versions, listed in this MSFT internal link
2525
# https://github.com/AzureAD/microsoft-authentication-library-for-cpp/pull/2406/files
26-
raise ImportError( # TODO: Remove or adjust this line right before merging this PR
27-
'You need to install dependency by: pip install "msal[broker]>=1.20,<2"')
26+
raise ImportError('You need to install dependency by: pip install "msal[broker]>=1.20,<2"')
2827
# It could throw RuntimeError when running on ancient versions of Windows
2928

3029

@@ -84,9 +83,11 @@ def _read_account_by_id(account_id, correlation_id):
8483

8584

8685
def _convert_result(result, client_id, expected_token_type=None): # Mimic an on-the-wire response from AAD
86+
telemetry = result.get_telemetry_data()
87+
telemetry.pop("wam_telemetry", None) # In pymsalruntime 0.13, it contains PII "account_id"
8788
error = result.get_error()
8889
if error:
89-
return _convert_error(error, client_id)
90+
return dict(_convert_error(error, client_id), _msalruntime_telemetry=telemetry)
9091
id_token_claims = json.loads(result.get_id_token()) if result.get_id_token() else {}
9192
account = result.get_account()
9293
assert account, "Account is expected to be always available"
@@ -107,7 +108,7 @@ def _convert_result(result, client_id, expected_token_type=None): # Mimic an on
107108
granted_scopes = result.get_granted_scopes() # New in pymsalruntime 0.3.x
108109
if granted_scopes:
109110
return_value["scope"] = " ".join(granted_scopes) # Mimic the on-the-wire data format
110-
return return_value
111+
return dict(return_value, _msalruntime_telemetry=telemetry)
111112

112113

113114
def _get_new_correlation_id():

0 commit comments

Comments
 (0)