mirror of
https://github.com/coddingtonbear/django-mailbox.git
synced 2026-07-10 06:48:19 +02:00
adds testable repo with added features
This commit is contained in:
parent
62805f324e
commit
c7997ebd9b
58 changed files with 2421 additions and 1541 deletions
|
|
@ -28,7 +28,7 @@ def get_google_access_token(email):
|
|||
# TODO: This should be cacheable
|
||||
try:
|
||||
me = UserSocialAuth.objects.get(uid=email, provider="google-oauth2")
|
||||
return me.extra_data['access_token']
|
||||
return me.extra_data["access_token"]
|
||||
except (UserSocialAuth.DoesNotExist, KeyError):
|
||||
raise AccessTokenNotFound
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ def update_google_extra_data(email, extra_data):
|
|||
def get_google_refresh_token(email):
|
||||
try:
|
||||
me = UserSocialAuth.objects.get(uid=email, provider="google-oauth2")
|
||||
return me.extra_data['refresh_token']
|
||||
return me.extra_data["refresh_token"]
|
||||
except (UserSocialAuth.DoesNotExist, KeyError):
|
||||
raise RefreshTokenNotFound
|
||||
|
||||
|
|
@ -72,9 +72,11 @@ def google_api_post(email, url, post_data, authorized=True):
|
|||
# TODO: Make this a lot less ugly. especially the 401 handling
|
||||
headers = dict()
|
||||
if authorized is True:
|
||||
headers.update(dict(
|
||||
Authorization="Bearer %s" % get_google_access_token(email),
|
||||
))
|
||||
headers.update(
|
||||
dict(
|
||||
Authorization="Bearer %s" % get_google_access_token(email),
|
||||
)
|
||||
)
|
||||
r = requests.post(url, headers=headers, data=post_data)
|
||||
if r.status_code == 401:
|
||||
refresh_authorization(email)
|
||||
|
|
@ -92,20 +94,20 @@ def refresh_authorization(email):
|
|||
refresh_token=refresh_token,
|
||||
client_id=get_google_consumer_key(),
|
||||
client_secret=get_google_consumer_secret(),
|
||||
grant_type='refresh_token',
|
||||
grant_type="refresh_token",
|
||||
)
|
||||
results = google_api_post(
|
||||
email,
|
||||
"https://accounts.google.com/o/oauth2/token?access_type=offline",
|
||||
post_data,
|
||||
authorized=False)
|
||||
results.update({'refresh_token': refresh_token})
|
||||
authorized=False,
|
||||
)
|
||||
results.update({"refresh_token": refresh_token})
|
||||
update_google_extra_data(email, results)
|
||||
|
||||
|
||||
def fetch_user_info(email):
|
||||
result = google_api_get(
|
||||
email,
|
||||
"https://www.googleapis.com/oauth2/v1/userinfo?alt=json"
|
||||
email, "https://www.googleapis.com/oauth2/v1/userinfo?alt=json"
|
||||
)
|
||||
return result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue