Public Member Functions | |
def | authenticate_redirect |
def | twitter_request |
Private Member Functions | |
def | _oauth_consumer_token |
def | _oauth_get_user_future |
def | _on_twitter_request |
Static Private Attributes | |
string | _OAUTH_ACCESS_TOKEN_URL = "https://api.twitter.com/oauth/access_token" |
string | _OAUTH_AUTHENTICATE_URL = "https://api.twitter.com/oauth/authenticate" |
string | _OAUTH_AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize" |
_OAUTH_NO_CALLBACKS = False | |
string | _OAUTH_REQUEST_TOKEN_URL = "https://api.twitter.com/oauth/request_token" |
string | _TWITTER_BASE_URL = "https://api.twitter.com/1.1" |
Twitter OAuth authentication. To authenticate with Twitter, register your application with Twitter at http://twitter.com/apps. Then copy your Consumer Key and Consumer Secret to the application `~tornado.web.Application.settings` ``twitter_consumer_key`` and ``twitter_consumer_secret``. Use this mixin on the handler for the URL you registered as your application's callback URL. When your application is set up, you can use this mixin like this to authenticate the user with Twitter and get access to their stream:: class TwitterLoginHandler(tornado.web.RequestHandler, tornado.auth.TwitterMixin): @tornado.gen.coroutine def get(self): if self.get_argument("oauth_token", None): user = yield self.get_authenticated_user() # Save the user using e.g. set_secure_cookie() else: yield self.authorize_redirect() The user object returned by `~OAuthMixin.get_authenticated_user` includes the attributes ``username``, ``name``, ``access_token``, and all of the custom Twitter user attributes described at https://dev.twitter.com/docs/api/1.1/get/users/show
def tornado.auth.TwitterMixin._oauth_consumer_token | ( | self | ) | [private] |
Subclasses must override this to return their OAuth consumer keys. The return value should be a `dict` with keys ``key`` and ``secret``.
Reimplemented from tornado.auth.OAuthMixin.
def tornado.auth.TwitterMixin._oauth_get_user_future | ( | self, | |
access_token | |||
) | [private] |
def tornado.auth.TwitterMixin._on_twitter_request | ( | self, | |
future, | |||
response | |||
) | [private] |
def tornado.auth.TwitterMixin.authenticate_redirect | ( | self, | |
callback_uri = None , |
|||
callback = None |
|||
) |
Just like `~OAuthMixin.authorize_redirect`, but auto-redirects if authorized. This is generally the right interface to use if you are using Twitter for single-sign on. .. versionchanged:: 3.1 Now returns a `.Future` and takes an optional callback, for compatibility with `.gen.coroutine`.
def tornado.auth.TwitterMixin.twitter_request | ( | self, | |
path, | |||
callback = None , |
|||
access_token = None , |
|||
post_args = None , |
|||
args | |||
) |
Fetches the given API path, e.g., ``statuses/user_timeline/btaylor`` The path should not include the format or API version number. (we automatically use JSON format and API version 1). If the request is a POST, ``post_args`` should be provided. Query string arguments should be given as keyword arguments. All the Twitter methods are documented at http://dev.twitter.com/ Many methods require an OAuth access token which you can obtain through `~OAuthMixin.authorize_redirect` and `~OAuthMixin.get_authenticated_user`. The user returned through that process includes an 'access_token' attribute that can be used to make authenticated requests via this method. Example usage:: class MainHandler(tornado.web.RequestHandler, tornado.auth.TwitterMixin): @tornado.web.authenticated @tornado.gen.coroutine def get(self): new_entry = yield self.twitter_request( "/statuses/update", post_args={"status": "Testing Tornado Web Server"}, access_token=self.current_user["access_token"]) if not new_entry: # Call failed; perhaps missing permission? yield self.authorize_redirect() return self.finish("Posted a message!")
string tornado::auth.TwitterMixin::_OAUTH_ACCESS_TOKEN_URL = "https://api.twitter.com/oauth/access_token" [static, private] |
string tornado::auth.TwitterMixin::_OAUTH_AUTHENTICATE_URL = "https://api.twitter.com/oauth/authenticate" [static, private] |
string tornado::auth.TwitterMixin::_OAUTH_AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize" [static, private] |
tornado::auth.TwitterMixin::_OAUTH_NO_CALLBACKS = False [static, private] |
string tornado::auth.TwitterMixin::_OAUTH_REQUEST_TOKEN_URL = "https://api.twitter.com/oauth/request_token" [static, private] |
string tornado::auth.TwitterMixin::_TWITTER_BASE_URL = "https://api.twitter.com/1.1" [static, private] |