From c08461cde81a98996e3e8d5f3a27bba897b12f97 Mon Sep 17 00:00:00 2001 From: Youssef Badzi <95358038+badziyoussef@users.noreply.github.com> Date: Mon, 30 Dec 2024 11:08:50 +0100 Subject: [PATCH] fix gmail get_access_token --- django_mailbox/google_utils.py | 3 +++ django_mailbox/transports/gmail.py | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/django_mailbox/google_utils.py b/django_mailbox/google_utils.py index c9c6301..0eabb42 100644 --- a/django_mailbox/google_utils.py +++ b/django_mailbox/google_utils.py @@ -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: diff --git a/django_mailbox/transports/gmail.py b/django_mailbox/transports/gmail.py index 2a00c93..68bce6a 100644 --- a/django_mailbox/transports/gmail.py +++ b/django_mailbox/transports/gmail.py @@ -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