
Public Member Functions | |
| def | facebook_request |
| def | get_auth_http_client |
| def | get_authenticated_user |
Private Member Functions | |
| def | _on_access_token |
| def | _on_facebook_request |
| def | _on_get_user_info |
Static Private Attributes | |
| string | _FACEBOOK_BASE_URL = "https://graph.facebook.com" |
| string | _OAUTH_ACCESS_TOKEN_URL = "https://graph.facebook.com/oauth/access_token?" |
| string | _OAUTH_AUTHORIZE_URL = "https://www.facebook.com/dialog/oauth?" |
| _OAUTH_NO_CALLBACKS = False | |
Facebook authentication using the new Graph API and OAuth2.
| def tornado.auth.FacebookGraphMixin._on_access_token | ( | self, | |
| redirect_uri, | |||
| client_id, | |||
| client_secret, | |||
| future, | |||
| fields, | |||
| response | |||
| ) | [private] |
| def tornado.auth.FacebookGraphMixin._on_facebook_request | ( | self, | |
| future, | |||
| response | |||
| ) | [private] |
| def tornado.auth.FacebookGraphMixin._on_get_user_info | ( | self, | |
| future, | |||
| session, | |||
| fields, | |||
| user | |||
| ) | [private] |
| def tornado.auth.FacebookGraphMixin.facebook_request | ( | self, | |
| path, | |||
| callback, | |||
access_token = None, |
|||
post_args = None, |
|||
| args | |||
| ) |
Fetches the given relative API path, e.g., "/btaylor/picture"
If the request is a POST, ``post_args`` should be provided. Query
string arguments should be given as keyword arguments.
An introduction to the Facebook Graph API can be found at
http://developers.facebook.com/docs/api
Many methods require an OAuth access token which you can
obtain through `~OAuth2Mixin.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.FacebookGraphMixin):
@tornado.web.authenticated
@tornado.gen.coroutine
def get(self):
new_entry = yield self.facebook_request(
"/me/feed",
post_args={"message": "I am posting from my Tornado application!"},
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!")
The given path is relative to ``self._FACEBOOK_BASE_URL``,
by default "https://graph.facebook.com".
.. versionchanged:: 3.1
Added the ability to override ``self._FACEBOOK_BASE_URL``.
| def tornado.auth.FacebookGraphMixin.get_authenticated_user | ( | self, | |
| redirect_uri, | |||
| client_id, | |||
| client_secret, | |||
| code, | |||
| callback, | |||
extra_fields = None |
|||
| ) |
Handles the login for the Facebook user, returning a user object.
Example usage::
class FacebookGraphLoginHandler(LoginHandler, tornado.auth.FacebookGraphMixin):
@tornado.gen.coroutine
def get(self):
if self.get_argument("code", False):
user = yield self.get_authenticated_user(
redirect_uri='/auth/facebookgraph/',
client_id=self.settings["facebook_api_key"],
client_secret=self.settings["facebook_secret"],
code=self.get_argument("code"))
# Save the user with e.g. set_secure_cookie
else:
yield self.authorize_redirect(
redirect_uri='/auth/facebookgraph/',
client_id=self.settings["facebook_api_key"],
extra_params={"scope": "read_stream,offline_access"})
string tornado::auth.FacebookGraphMixin::_FACEBOOK_BASE_URL = "https://graph.facebook.com" [static, private] |
string tornado::auth.FacebookGraphMixin::_OAUTH_ACCESS_TOKEN_URL = "https://graph.facebook.com/oauth/access_token?" [static, private] |
string tornado::auth.FacebookGraphMixin::_OAUTH_AUTHORIZE_URL = "https://www.facebook.com/dialog/oauth?" [static, private] |
tornado::auth.FacebookGraphMixin::_OAUTH_NO_CALLBACKS = False [static, private] |