-
Notifications
You must be signed in to change notification settings - Fork 205
Actionable exception from ADFS username password flow #456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1417,12 +1417,18 @@ def acquire_token_by_username_password( | |
user_realm_result = self.authority.user_realm_discovery( | ||
username, correlation_id=headers[msal.telemetry.CLIENT_REQUEST_ID]) | ||
if user_realm_result.get("account_type") == "Federated": | ||
response = _clean_up(self._acquire_token_by_username_password_federated( | ||
user_realm_result, username, password, scopes=scopes, | ||
data=data, | ||
headers=headers, **kwargs)) | ||
telemetry_context.update_telemetry(response) | ||
return response | ||
try: | ||
response = _clean_up(self._acquire_token_by_username_password_federated( | ||
user_realm_result, username, password, scopes=scopes, | ||
data=data, | ||
headers=headers, **kwargs)) | ||
except (ValueError, RuntimeError): | ||
raise RuntimeError( | ||
"ADFS is not configured properly. " | ||
"Consider use acquire_token_interactive() instead.") | ||
Comment on lines
+1426
to
+1428
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about we include the original exception as an "inner" exception? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Currently, the "inner" exception would show up in Python3's error trace already, therefore visible by default. However, I would expect Azure CLI to do this, to have an actionable guidance most suitable in the Azure CLI's context: try:
result = app.acquire_token_by_username_password(...)
except RuntimeError:
raise CLIError('Username password login failed. You may consider using "az login" instead.') There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Won't "Username password login failed" be too vague? This exception chaining pattern is difficult for Azure CLI to get the inner exception message, like that of the original There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can probably print the exception you caught. It would contain some (perhaps too much) info. Alas, it is hard to strike a balance here. :-( try:
result = app.acquire_token_by_username_password(...)
except RuntimeError as e:
raise CLIError('Username password login failed: {}. You may consider using "az login" instead.'.format(e)) |
||
else: | ||
telemetry_context.update_telemetry(response) | ||
return response | ||
response = _clean_up(self.client.obtain_token_by_username_password( | ||
username, password, scope=scopes, | ||
headers=headers, | ||
|
Uh oh!
There was an error while loading. Please reload this page.