10000 Merge pull request #20 from Microsoft/johtaylo/msftappcred-with-emulator · openvelora/botbuilder-python@8544e7e · GitHub
[go: up one dir, main page]

Skip to content

Commit 8544e7e

Browse files
authored
Merge pull request microsoft#20 from Microsoft/johtaylo/msftappcred-with-emulator
added checkin for empty user and pwd fields. Reviewed in person with John Taylor. GitHub Review system seems to be offline.
2 parents d0d5f01 + 43f5ba1 commit 8544e7e

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,23 @@ def signed_session(self):
5858
return basic_authentication.signed_session()
5959

6060
def get_access_token(self, force_refresh=False):
61-
if not force_refresh:
62-
# check the global cache for the token. If we have it, and it's valid, we're done.
63-
oauth_token = MicrosoftAppCredentials.cache.get(self.token_cache_key, None)
64-
if oauth_token is not None:
65-
# we have the token. Is it valid?
66-
if oauth_token.expiration_time > datetime.now():
67-
return oauth_token.access_token
68-
# We need to refresh the token, because:
69-
# 1. The user requested it via the force_refresh parameter
70-
# 2. We have it, but it's expired
71-
# 3. We don't have it in the cache.
72-
oauth_token = self.refresh_token()
73-
MicrosoftAppCredentials.cache.setdefault(self.token_cache_key, oauth_token)
74-
return oauth_token.access_token
61+
if self.microsoft_app_id and self.microsoft_app_password:
62+
if not force_refresh:
63+
# check the global cache for the token. If we have it, and it's valid, we're done.
64+
oauth_token = MicrosoftAppCredentials.cache.get(self.token_cache_key, None)
65+
if oauth_token is not None:
66+
# we have the token. Is it valid?
67+
if oauth_token.expiration_time > datetime.now():
68+
return oauth_token.access_token
69+
# We need to refresh the token, because:
70+
# 1. The user requested it via the force_refresh parameter
71+
# 2. We have it, but it's expired
72+
# 3. We don't have it in the cache.
73+
oauth_token = self.refresh_token()
74+
MicrosoftAppCredentials.cache.setdefault(self.token_cache_key, oauth_token)
75+
return oauth_token.access_token
76+
else:
77+
return ''
7578

7679
def refresh_token(self):
7780
options = {

0 commit comments

Comments
 (0)
0