Skip to content

Instantly share code, notes, and snippets.

@mikej165
Created December 22, 2014 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikej165/6521d4edeb507f2d9d95 to your computer and use it in GitHub Desktop.
Save mikej165/6521d4edeb507f2d9d95 to your computer and use it in GitHub Desktop.
class GoogleSignIn(OAuthSignIn):
def __init__(self):
super(GoogleSignIn, self).__init__('google')
self.service = OAuth2Service(
name='google',
client_id=self.consumer_id,
client_secret=self.consumer_secret,
authorize_url='https://accounts.google.com/o/oauth2/auth',
access_token_url='https://accounts.google.com/o/oauth2/token',
base_url='https://www.googleapis.com/plus/v1/people/'
)
def authorize(self):
return redirect(self.service.get_authorize_url(
scope='email',
response_type='code',
redirect_uri=self.get_callback_url())
)
def callback(self):
if 'code' not in request.args:
return None, None, None
oauth_session = self.service.get_auth_session(
data={'code': request.args['code'],
'grant_type': 'authorization_code',
'redirect_uri': self.get_callback_url()},
decoder=json.loads
)
me = json.loads(oauth_session.get('me').text)
me_email = None
for e in me['emails']:
if e['type'] == 'account':
me_email = e['value']
return (
me.get('id'),
me.get('displayName'),
me_email)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment