Skip to content

Commit

Permalink
address oauth scenario for msi token (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
williexu authored Aug 29, 2018
1 parent 3a2ca20 commit 74592da
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/storage-preview/azext_storage_preview/oauth_token_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ def timer_callback(self):
from datetime import datetime
# should give back token that is valid for at least 5 mins
token = Profile(cli_ctx=self.cli_ctx).get_raw_token(resource="https://storage.azure.com")[0][2]
self.token_credential.token = token['accessToken']
seconds_left = (datetime.strptime(token['expiresOn'], "%Y-%m-%d %H:%M:%S.%f") - datetime.now()).seconds
try:
self.token_credential.token = token['accessToken']
seconds_left = (datetime.strptime(token['expiresOn'], "%Y-%m-%d %H:%M:%S.%f") - datetime.now()).seconds
except KeyError: # needed to deal with differing unserialized MSI token payload
self.token_credential.token = token['access_token']
seconds_left = (datetime.fromtimestamp(int(token['expires_on'])) - datetime.now()).seconds
if seconds_left < 240:
# acquired token expires in less than 4 mins
raise Exception("Acquired a token expiring in less than 4 minutes")
Expand Down

0 comments on commit 74592da

Please sign in to comment.