Skip to content
Next Next commit
Google_oauth2 get optional fields without KeyError.
  • Loading branch information
katzlbt committed Feb 16, 2015
commit 54401f94b5a3115771e3b6a7141d1415fc6ebd35
17 changes: 7 additions & 10 deletions velruse/providers/google_oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,14 @@ def callback(self, request):
data = r.json()
profile['accounts'] = [{
'domain': self.domain,
'username': data['email'],
'userid': data['id']
'username': data.get('email'),
'userid': data.get('id')
}]
if 'name' in data:
profile['displayName'] = data['name']
else:
profile['displayName'] = data['email']
profile['preferredUsername'] = data['email']
profile['verifiedEmail'] = data['email']
profile['emails'] = [{'value': data['email']}]

profile['displayName'] = data.get('name')
profile['preferredUsername'] = data.get('email')
profile['verifiedEmail'] = data.get('email')
profile['emails'] = [{'value': data.get('email')}]

cred = {'oauthAccessToken': access_token,
'oauthRefreshToken': refresh_token}
return GoogleAuthenticationComplete(profile=profile,
Expand Down