Public Member Functions | Private Member Functions | Static Private Attributes
tornado.auth.TwitterMixin Class Reference
Inheritance diagram for tornado.auth.TwitterMixin:
Inheritance graph
[legend]

List of all members.

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"

Detailed Description

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

Definition at line 621 of file auth.py.


Member Function Documentation

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.

Definition at line 743 of file auth.py.

def tornado.auth.TwitterMixin._oauth_get_user_future (   self,
  access_token 
) [private]

Definition at line 751 of file auth.py.

def tornado.auth.TwitterMixin._on_twitter_request (   self,
  future,
  response 
) [private]

Definition at line 735 of file auth.py.

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`.

Definition at line 657 of file auth.py.

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!")

Definition at line 675 of file auth.py.


Member Data Documentation

string tornado::auth.TwitterMixin::_OAUTH_ACCESS_TOKEN_URL = "https://api.twitter.com/oauth/access_token" [static, private]

Definition at line 650 of file auth.py.

string tornado::auth.TwitterMixin::_OAUTH_AUTHENTICATE_URL = "https://api.twitter.com/oauth/authenticate" [static, private]

Definition at line 652 of file auth.py.

string tornado::auth.TwitterMixin::_OAUTH_AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize" [static, private]

Definition at line 651 of file auth.py.

Definition at line 653 of file auth.py.

string tornado::auth.TwitterMixin::_OAUTH_REQUEST_TOKEN_URL = "https://api.twitter.com/oauth/request_token" [static, private]

Definition at line 649 of file auth.py.

string tornado::auth.TwitterMixin::_TWITTER_BASE_URL = "https://api.twitter.com/1.1" [static, private]

Definition at line 654 of file auth.py.


The documentation for this class was generated from the following file:


rosbridge_server
Author(s): Jonathan Mace
autogenerated on Thu Aug 27 2015 14:50:40