Skip to content
Open
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
Updating Google OAuth2 userinfo endpoint to current version and exp…
…anding profile info
  • Loading branch information
seedifferently committed Feb 13, 2014
commit 2757130015ee06d41358ee65608ae17318c464b6
26 changes: 21 additions & 5 deletions velruse/providers/google_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ def add_google_login(config,

class GoogleOAuth2Provider(object):

profile_scope = 'https://www.googleapis.com/auth/userinfo.profile'
email_scope = 'https://www.googleapis.com/auth/userinfo.email'
profile_scope = 'profile'
email_scope = 'email'

def __init__(self,
name,
Expand Down Expand Up @@ -155,7 +155,7 @@ def callback(self, request):
# Retrieve profile data if scopes allow
profile = {}
user_url = flat_url(
'%s://www.googleapis.com/oauth2/v1/userinfo' % self.protocol,
'%s://www.googleapis.com/oauth2/v2/userinfo' % self.protocol,
access_token=access_token)
r = requests.get(user_url)

Expand All @@ -171,8 +171,24 @@ def callback(self, request):
else:
profile['displayName'] = data['email']
profile['preferredUsername'] = data['email']
profile['verifiedEmail'] = data['email']
profile['emails'] = [{'value': data['email']}]
profile['emails'] = [{'value': data['email'], 'primary': True}]
if data.get('verified_email'):
profile['verifiedEmail'] = data['email']
if 'given_name' in data and 'family_name' in data:
profile['name'] = {
'familyName': data['family_name'],
'givenName': data['given_name']
}
if 'gender' in data:
profile['gender'] = data['gender']
if 'picture' in data:
profile['photos'] = [{'value': data['picture']}]
if 'locale' in data:
profile['locale'] = data['locale']
if 'link' in data:
profile['urls'] = [{'value': data['link'], 'type': 'profile'}]
if 'hd' in data: # Hosted domain (e.g. if the user is Google apps)
profile['hostedDomain'] = data['hd']

cred = {'oauthAccessToken': access_token,
'oauthRefreshToken': refresh_token}
Expand Down