diff --git a/tornado/cnauth.py b/tornado/cnauth.py new file mode 100644 index 0000000000..4d224970d6 --- /dev/null +++ b/tornado/cnauth.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python +#-*-coding: utf-8 -*- +""" + author comger@gmail.com +""" +from tornado import httpclient +from tornado.httputil import url_concat +from tornado.auth import OAuth2Mixin +import logging,json +import urllib + + + +class WeiboAuth2Minix(OAuth2Mixin): + """docstring for WeiboAuth2Minix""" + _OAUTH_AUTHORIZE_URL = "https://api.weibo.com/oauth2/authorize" + _OAUTH_ACCESS_TOKEN_URL = "https://api.weibo.com/oauth2/access_token" + + + def authorize_redirect(self, redirect_uri,client_id,client_secret = None, extra_params=None ): + """调用父类方法跳转认证获取code, Weibo认证需要加入 + 参数response_type:(code)和state所以作为附加参数传递给父类方法""" + args = { + "response_type" : "code", + } + if extra_params: + args.update(extra_params) + + super(WeiboAuth2Minix, self).authorize_redirect(redirect_uri,client_id,client_secret, + args) + + + def get_authenticated_user(self, code, redirect_uri ,client_id,client_secret, callback, extra_params=None ): + ''' get logined user info ''' + args = { + "redirect_uri":redirect_uri, + "code":code, + "client_id":client_id, + "client_secret":client_secret + } + + def get_user(res): + api = url_concat('https://api.weibo.com/2/users/show.json',res) + self.get_auth_http_client().fetch(api,callback = callback) + + + self.get_access_token(get_user, **args) + + + def parse_access_token(self, response, callback): + ''' loads json and callback result''' + res = json.loads(response.body) + if res.get('error',None): + callback(None) + return + + self.set_secure_cookie('access_token',res['access_token']) + callback(res) + + + def get_access_token(self, callback = None, **kwargs): + + def parse(response): + self.parse_access_token(response, callback) + + self.get_auth_http_client().fetch(self._OAUTH_ACCESS_TOKEN_URL,method = "POST", body = urllib.urlencode(kwargs), callback = parse) + + + def reply_mblog(self, mid, comment, callback): + ''' 回复微博信息 + + mid : 微博id, + comment : 回复内容 + ''' + api = 'https://api.weibo.com/2/comments/create.json' + data = dict(id= mid, comment = comment) + data.update(access_token = self.get_secure_cookie('access_token')) + self.get_auth_http_client().fetch(api,method = "POST", body = urllib.urlencode(data), callback = callback) + + + def get_auth_http_client(self): + return httpclient.AsyncHTTPClient() diff --git a/website/sphinx/index.rst b/website/sphinx/index.rst index ebf9e6865a..cd15ca2f83 100644 --- a/website/sphinx/index.rst +++ b/website/sphinx/index.rst @@ -1,5 +1,8 @@ .. title:: Tornado Web Server +.. meta:: + :google-site-verification: g4bVhgwbVO1d9apCUsT-eKlApg31Cygbp8VGZY8Rf0g + |Tornado Web Server| ==================== @@ -22,7 +25,7 @@ reasonably fast. Because it is non-blocking and uses `epoll or ``kqueue``, it can handle thousands of simultaneous standing connections, which means it is ideal for real-time web services. We built the web server specifically to handle FriendFeed's real-time -features — every active user of FriendFeed maintains an open +features — every active user of FriendFeed maintains an open connection to the FriendFeed servers. (For more information on scaling servers to support thousands of clients, see The `C10K problem `_.) @@ -33,14 +36,14 @@ Upgrading from Tornado 1.x Tornado 2.0 introduces several potentially backwards-incompatible changes, including in particular automatic escaping of template output. Users who are upgrading from Tornado 1.x should see the -`version 2.0 release notes `_ for +:doc:`version 2.0 release notes ` for information about backwards compatibility. Quick links ----------- -* `Documentation `_ -* |Download current version|: :current_tarball:`z` (`release notes `_) +* :doc:`Documentation ` +* |Download current version|: :current_tarball:`z` (:doc:`release notes `) * `Source (github) `_ * `Mailing list `_ * `Wiki `_ @@ -65,9 +68,9 @@ Here is the canonical "Hello, world" example app for Tornado:: if __name__ == "__main__": application.listen(8888) - tornado.ioloop.IOLoop.instance().start() + tornado.ioloop.IOLoop.instance().start() -See the `Tornado documentation `_ for a +See the :doc:`Tornado documentation ` for a detailed walkthrough of the framework. Installation @@ -134,4 +137,3 @@ Commons 3.0 `_. :hidden: documentation - diff --git a/website/static/sphinx.css b/website/static/sphinx.css index de4d690b1b..6c56f75792 100644 --- a/website/static/sphinx.css +++ b/website/static/sphinx.css @@ -64,4 +64,8 @@ div.related, div.sphinxsidebar { div.section { max-width: 850px; +} + +a.reference.internal em { + font-style: normal; } \ No newline at end of file