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
def _on_twitter_request
def _parse_user_response

Static Private Attributes

string _OAUTH_ACCESS_TOKEN_URL = "http://api.twitter.com/oauth/access_token"
string _OAUTH_AUTHENTICATE_URL = "http://api.twitter.com/oauth/authenticate"
string _OAUTH_AUTHORIZE_URL = "http://api.twitter.com/oauth/authorize"
 _OAUTH_NO_CALLBACKS = False
string _OAUTH_REQUEST_TOKEN_URL = "http://api.twitter.com/oauth/request_token"

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 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 TwitterHandler(tornado.web.RequestHandler,
                         tornado.auth.TwitterMixin):
        @tornado.web.asynchronous
        def get(self):
            if self.get_argument("oauth_token", None):
                self.get_authenticated_user(self.async_callback(self._on_auth))
                return
            self.authorize_redirect()

        def _on_auth(self, user):
            if not user:
                raise tornado.web.HTTPError(500, "Twitter auth failed")
            # Save the user using, e.g., set_secure_cookie()

The user object returned by get_authenticated_user() includes the
attributes 'username', 'name', and all of the custom Twitter user
attributes describe at
http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-users%C2%A0show
in addition to 'access_token'. You should save the access token with
the user; it is required to make requests on behalf of the user later
with twitter_request().

Definition at line 427 of file auth.py.


Member Function Documentation

Definition at line 548 of file auth.py.

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

Reimplemented from tornado.auth.OAuthMixin.

Definition at line 555 of file auth.py.

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

Definition at line 540 of file auth.py.

def tornado.auth.TwitterMixin._parse_user_response (   self,
  callback,
  user 
) [private]

Definition at line 561 of file auth.py.

def tornado.auth.TwitterMixin.authenticate_redirect (   self,
  callback_uri = None 
)
Just like authorize_redirect(), but auto-redirects if authorized.

This is generally the right interface to use if you are using
Twitter for single-sign on.

Definition at line 467 of file auth.py.

def tornado.auth.TwitterMixin.twitter_request (   self,
  path,
  callback,
  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 (we automatically append
".json" and parse the JSON output).

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://apiwiki.twitter.com/Twitter-API-Documentation.

Many methods require an OAuth access token which you can obtain
through authorize_redirect() and 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.web.asynchronous
def get(self):
    self.twitter_request(
        "/statuses/update",
        post_args={"status": "Testing Tornado Web Server"},
        access_token=user["access_token"],
        callback=self.async_callback(self._on_post))

def _on_post(self, new_entry):
    if not new_entry:
        # Call failed; perhaps missing permission?
        self.authorize_redirect()
        return
    self.finish("Posted a message!")

Definition at line 477 of file auth.py.


Member Data Documentation

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

Definition at line 462 of file auth.py.

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

Definition at line 464 of file auth.py.

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

Definition at line 463 of file auth.py.

Definition at line 465 of file auth.py.

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

Definition at line 461 of file auth.py.


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


rosbridge_server
Author(s): Jonathan Mace
autogenerated on Mon Oct 6 2014 06:58:14