question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Identity] Azure Identity should expose the original MSAL error

See original GitHub issue

Is your feature request related to a problem? Please describe.

When AuthenticationRequiredError is raised, the original MSAL result (error dict) is discarded:

https://github.com/Azure/azure-sdk-for-python/blob/ef46a5c14a3c49c040a124d9c626c77cf2964cdc/sdk/identity/azure-identity/azure/identity/_internal/interactive.py#L198-L202

This makes aad_exception_handler (https://github.com/Azure/azure-cli/pull/17072) impossible to handle MSAL error directly.

Describe the solution you’d like

AuthenticationRequiredError should have an attribute referring to the original MSAL result.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
rayluocommented, Mar 8, 2021

If MSAL raised an Exception instead of an error dict, we would be supposed to use Exception Chaining

From MSAL’s perspective, an error response is equally likely as a successful response, so the return value is a dict in both cases. But feel free to wrap it inside an exception as you see fit.

By the way, that Exception Chaining was introduced since Python 3.3. This might not be a problem for Azure CLI as an application, but historically Azure Identity and MSAL work with Python 2.7 too.

specify a smaller subset of those raw fields

Maybe we can start with error and error_description, which are mentioned in the OAuth2 specs. I don’t see them going away in the future. The correlation_id is an AAD practice that could also be helpful during troubleshooting, if the customer does not have other ways to obtain it.

0reactions
chlowellcommented, Mar 18, 2021

As discussed offline, I’ve opened a PR to address this by attaching Azure AD’s HTTP response to authentication exceptions whenever possible. That will provide all the information returned by MSAL after an auth failure while remaining consistent with exceptions raised by credentials that do not use MSAL.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle errors and exceptions in MSAL.NET - Microsoft Entra
Learn how to handle errors and exceptions, Conditional Access claims challenges, and retries in MSAL.NET.
Read more >
MsalError Class (Microsoft.Identity.Client) - Azure for .NET ...
The client is unauthorized to access resource. This commonly happens when Mobile App Management (MAM) policies are enabled. MSAL will throw an exception...
Read more >
Acquire and cache tokens with Microsoft Authentication ...
MSAL allows you to get tokens to access Azure AD for developers (v1.0) and the Microsoft identity platform APIs. v2.0 protocol uses scopes ......
Read more >
Unable to use AddSignIn Method of Microsoft.Identity.Web ...
We want to use MSAL for Authentication in our Web application with Web API using Authorization Code Flow.
Read more >
Azure Identity client library for JavaScript | Microsoft Learn
Most of the credential types offered by @azure/identity use the Microsoft Authentication Library for JavaScript (MSAL.js).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found