Skip to content

Commit

Permalink
fix(auth): handle cases of missing google refresh token
Browse files Browse the repository at this point in the history
  • Loading branch information
mwfarb committed Sep 25, 2024
1 parent e9b4ab6 commit 7c28970
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions arena/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,17 @@ def authenticate_user(self, web_host, headless):
except (json.JSONDecodeError, UnicodeDecodeError):
creds = None # bad/old storage format

if creds:
# for reuse, client_id must still match
if creds and "id_token" in creds:
id_claims = gJWT.decode(creds["id_token"], verify=False)
# for reuse, client_id must still match
if id_claims["aud"] != gauth["installed"]["client_id"]:
creds = None # switched auth systems
if creds and "refresh_token" in creds and "exp" in id_claims:
exp = float(id_claims["exp"])
if exp <= time.time():
refresh_token = creds["refresh_token"]
creds = None # expired token
if creds and "refresh_token" in creds:
refresh_token = creds["refresh_token"]
if creds and id_claims:
exp = float(id_claims["exp"])
if exp <= time.time():
creds = None # expired token

if creds:
print("Using cached Google authentication.")
Expand Down

0 comments on commit 7c28970

Please # to comment.