Skip to content

Commit

Permalink
Port auth error handling from microsoft_app_credentials to certificat…
Browse files Browse the repository at this point in the history
…e_app_credentials (#2196)

Co-authored-by: Konstantin Plis <konstantin.plis@acronis.com>
  • Loading branch information
kostyaplis and Konstantin Plis authored Jan 6, 2025
1 parent a7f5d91 commit ef5ecd3
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,17 @@ def get_access_token(self, force_refresh: bool = False) -> str:
if not auth_token:
# No suitable token exists in cache. Let's get a new one from AAD.
auth_token = self.__get_msal_app().acquire_token_for_client(scopes=scopes)
return auth_token["access_token"]
if "access_token" in auth_token:
return auth_token["access_token"]
error = auth_token["error"] if "error" in auth_token else "Unknown error"
error_description = (
auth_token["error_description"]
if "error_description" in auth_token
else "Unknown error description"
)
raise PermissionError(
f"Failed to get access token with error: {error}, error_description: {error_description}"
)

def __get_msal_app(self):
if not self.app:
Expand Down

0 comments on commit ef5ecd3

Please sign in to comment.