Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix retrieving google oauth token #304

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions django_mailbox/google_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ def google_api_get(email, url):
if r.status_code == 401:
# Go use the refresh token
refresh_authorization(email)
# Force use of the new token
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
4 changes: 3 additions & 1 deletion django_mailbox/transports/gmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@ def _connect_oauth(self, username):
access_token = None
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