Skip to content

Raise the original error when refreshing token fails #431

Closed
@jiasli

Description

@jiasli

Describe the bug

Currently when refreshing token fails, MSAL silences the exception and logs and error:

except: # The exact HTTP exception is transportation-layer dependent
logger.exception("Refresh token failed") # Potential AAD outage?

ERROR    msal.application:application.py:1152 Refresh token failed
Traceback (most recent call last):
  File "C:\Users\user1\Desktop\project\env\lib\site-packages\urllib3\connectionpool.py", line 699, in urlopen
    httplib_response = self._make_request(
...
  File "C:\Program Files\Python38\lib\ssl.py", line 1173, in send
    return self._sslobj.write(data)
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\user1\Desktop\project\env\lib\site-packages\requests\adapters.py", line 439, in send
    resp = conn.urlopen(
...
  File "C:\Users\user1\Desktop\project\env\lib\site-packages\requests\adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', ConnectionResetError(10054, 'An existing connection was forcibly closed by the remote host', None, 10054, None))

Currently Azure CLI doesn't print MSAL's logs, the real cause will be hidden and all Azure CLI can get is a None result. Making it impossible for the end user to know what happened:

https://github.com/Azure/azure-cli/blob/925d5f93e9caff6fdc74c03b3755d8811d2baf69/src/azure-cli-core/azure/cli/core/auth/util.py#L119-L121

    if not result:
        raise AuthenticationError("Can't find token from MSAL cache.",
                                  recommendation="To re-authenticate, please run:\naz login")

This topic is very similar to the one we discussed in AzureAD/microsoft-authentication-extensions-for-python#92.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions