Skip to content

Instantly share code, notes, and snippets.

@wsantos
Created June 17, 2013 13:07
Show Gist options
  • Save wsantos/5796726 to your computer and use it in GitHub Desktop.
Save wsantos/5796726 to your computer and use it in GitHub Desktop.
Twitter Tornado sample
class AuthTwitterLoginHandler(LoginHandler, tornado.auth.TwitterMixin):
@tornado.web.asynchronous
@gen.engine
def get(self):
my_url = (self.request.protocol + "://" + self.request.host +
"/auth/twitter?next=" +
tornado.escape.url_escape(self.get_argument("next", "/")))
if self.get_argument("oauth_token", None):
user = yield gen.Task(self.get_authenticated_user)
if not user:
raise tornado.web.HTTPError(500, "Twitter auth failed")
r_user = yield gen.Task(self.upsert_provider, user, "twitter")
self.set_secure_cookie("user", tornado.escape.json_encode(r_user))
self.redirect(self.get_argument("next", "/"))
else:
self.authenticate_redirect(callback_uri=my_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment