Skip to content

Commit 1c801c3

Browse files
committed
Actionable exception from ADFS ROPC
1 parent 57ad763 commit 1c801c3

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

msal/application.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,12 +1417,18 @@ def acquire_token_by_username_password(
14171417
user_realm_result = self.authority.user_realm_discovery(
14181418
username, correlation_id=headers[msal.telemetry.CLIENT_REQUEST_ID])
14191419
if user_realm_result.get("account_type") == "Federated":
1420-
response = _clean_up(self._acquire_token_by_username_password_federated(
1421-
user_realm_result, username, password, scopes=scopes,
1422-
data=data,
1423-
headers=headers, **kwargs))
1424-
telemetry_context.update_telemetry(response)
1425-
return response
1420+
try:
1421+
response = _clean_up(self._acquire_token_by_username_password_federated(
1422+
user_realm_result, username, password, scopes=scopes,
1423+
data=data,
1424+
headers=headers, **kwargs))
1425+
except (ValueError, RuntimeError):
1426+
raise RuntimeError(
1427+
"ADFS is not configured properly. "
1428+
"Consider use acquire_token_interactive() instead.")
1429+
else:
1430+
telemetry_context.update_telemetry(response)
1431+
return response
14261432
response = _clean_up(self.client.obtain_token_by_username_password(
14271433
username, password, scope=scopes,
14281434
headers=headers,

msal/wstrust_request.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ def send_request(
4444
soap_action = Mex.ACTION_2005
4545
elif '/trust/13/usernamemixed' in endpoint_address:
4646
soap_action = Mex.ACTION_13
47-
assert soap_action in (Mex.ACTION_13, Mex.ACTION_2005), ( # A loose check here
48-
"Unsupported soap action: %s" % soap_action)
47+
if soap_action not in (Mex.ACTION_13, Mex.ACTION_2005):
48+
raise ValueError("Unsupported soap action: %s" % soap_action)
4949
data = _build_rst(
5050
username, password, cloud_audience_urn, endpoint_address, soap_action)
5151
resp = http_client.post(endpoint_address, data=data, headers={

0 commit comments

Comments
 (0)