Skip to content

Commit

Permalink
refactor token
Browse files Browse the repository at this point in the history
  • Loading branch information
nikellepetrillo committed Dec 12, 2024
1 parent 2f0d118 commit 4b179f8
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions scripts/firecloud_api/firecloud_api2.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,15 @@ def get_user_token(self, credentials: credentials):
if not credentials.valid:
logging.info("Fetching user's new access token")
credentials.refresh(Request())
logging.info("Token refreshed.")
else:
expiry_timestamp = credentials.expiry.replace(tzinfo=timezone.utc).timestamp()
now_timestamp = datetime.now(timezone.utc).timestamp()
# if token is about to expire in 1 minute, refresh and then use it
if expiry_timestamp - now_timestamp < 60:
logging.info("Fetching user's new access token")
credentials.refresh(Request())
logging.info("Token refreshed.")

return credentials.token

Expand Down

0 comments on commit 4b179f8

Please sign in to comment.