8000 get_access_token: error checking · microsoft/botbuilder-python@5e073e0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e073e0

Browse files
committed
get_access_token: error checking
In case if msal_app().acquire_token_silent() returns an error raise an exception with error details instead of crashing with KeyError
1 parent 3d41036 commit 5e073e0

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

libraries/botframework-connector/botframework/connector/auth/microsoft_app_credentials.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ def get_access_token(self, force_refresh: bool = False) -> str:
6262
auth_token = self.__get_msal_app().acquire_token_for_client(
6363
scopes=self.scopes
6464
)
65+
66+
# acquire_token...() returns None if there are no any tokens and
67+
# a dict which contains 'error' in case of error
68+
if auth_token is None:
69+
raise UserWarning("No any access tokens")
70+
if 'error' in auth_token:
71+
raise UserWarning(f"Failed to get access token: {auth_token}")
72+
6573
return auth_token["access_token"]
6674

6775
def __get_msal_app(self):

0 commit comments

Comments
 (0)
0