Skip to content

Commit

Permalink
fix gmail get_access_token
Browse files Browse the repository at this point in the history
  • Loading branch information
badziyoussef committed Dec 30, 2024
1 parent aef4e66 commit c08461c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions django_mailbox/google_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def google_api_get(email, url):
if r.status_code == 401:
# Go use the refresh token
refresh_authorization(email)
headers = dict(
Authorization="Bearer %s" % get_google_access_token(email),
)
r = requests.get(url, headers=headers)
logger.info("I got a %s", r.status_code)
if r.status_code == 200:
Expand Down
5 changes: 3 additions & 2 deletions django_mailbox/transports/gmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ def _connect_oauth(self, username):
)

access_token = None
google_email_address = username
while access_token is None:
try:
access_token = get_google_access_token(username)
# token refreshed here when expired
google_email_address = fetch_user_info(username)['email']
# retrieve token from db
access_token = get_google_access_token(username)
except TypeError:
# This means that the google process took too long
# Trying again is the right thing to do
Expand Down

0 comments on commit c08461c

Please sign in to comment.