Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branch2.4 #770

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
82 changes: 82 additions & 0 deletions 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()
16 changes: 9 additions & 7 deletions website/sphinx/index.rst
@@ -1,5 +1,8 @@
.. title:: Tornado Web Server

.. meta::
:google-site-verification: g4bVhgwbVO1d9apCUsT-eKlApg31Cygbp8VGZY8Rf0g

|Tornado Web Server|
====================

Expand All @@ -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
<http://www.kegel.com/c10k.html>`_.)
Expand All @@ -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 </documentation/releases/v2.0.0.html>`_ for
:doc:`version 2.0 release notes <releases/v2.0.0>` for
information about backwards compatibility.

Quick links
-----------

* `Documentation <documentation.html>`_
* |Download current version|: :current_tarball:`z` (`release notes </documentation/releases.html>`_)
* :doc:`Documentation <documentation>`
* |Download current version|: :current_tarball:`z` (:doc:`release notes <releases>`)
* `Source (github) <https://github.com/facebook/tornado>`_
* `Mailing list <http://groups.google.com/group/python-tornado>`_
* `Wiki <https://github.com/facebook/tornado/wiki/Links>`_
Expand All @@ -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()</code></pre>
tornado.ioloop.IOLoop.instance().start()

See the `Tornado documentation </documentation/index.html>`_ for a
See the :doc:`Tornado documentation <documentation>` for a
detailed walkthrough of the framework.

Installation
Expand Down Expand Up @@ -134,4 +137,3 @@ Commons 3.0 <http://creativecommons.org/licenses/by/3.0/>`_.
:hidden:

documentation

4 changes: 4 additions & 0 deletions website/static/sphinx.css
Expand Up @@ -64,4 +64,8 @@ div.related, div.sphinxsidebar {

div.section {
max-width: 850px;
}

a.reference.internal em {
font-style: normal;
}