Skip to content

Instantly share code, notes, and snippets.

@gdemir
Created April 16, 2015 06:43
Show Gist options
  • Save gdemir/64a9f2d00ad692858e37 to your computer and use it in GitHub Desktop.
Save gdemir/64a9f2d00ad692858e37 to your computer and use it in GitHub Desktop.
class GoogleOAuth2LoginHandler(tornado.web.RequestHandler, tornado.auth.GoogleOAuth2Mixin):
@tornado.gen.coroutine
def get(self):
print "geldik aha oluyor gibi"
if self.get_argument('code', False):
print "bulduk geldik hani nerde?"
user = yield self.get_authenticated_user(
redirect_uri='http://localhost:8888/google',
code=self.get_argument('code'))
http=tornado.httpclient.AsyncHTTPClient()
auth_string = "%s %s" % (user['token_type'], user['access_token'])
response = yield http.fetch('https://www.googleapis.com/userinfo/v2/me',headers={"Authorization": auth_string})
user = json.loads(response.body)
email = user['email']
print user
# Save the user with e.g. set_secure_cookie
else:
print "bulamadik gidiyoruz"
yield self.authorize_redirect(
redirect_uri='http://localhost:8888/google',
client_id=self.settings['google_oauth']['key'],
scope=['profile', 'email'],
response_type='code',
extra_params={'approval_prompt': 'auto'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment