Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Branch2.4 #770

Closed
wants to merge 4 commits into from

2 participants

@comger

add a sina weibo oauth2 class.
functuin list
1. update access_token
2. auto login
3. get current user info
4. reply blog

@bdarnell
Owner

This pull request picked up some unrelated commits, so I'll reply in the other one, #769.

@bdarnell bdarnell closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 10, 2013
  1. @bdarnell

    Fix broken links

    bdarnell authored
Commits on Mar 12, 2013
  1. @bdarnell
Commits on Mar 13, 2013
  1. @bdarnell
Commits on Apr 27, 2013
  1. add cnauth

    comger authored
This page is out of date. Refresh to see the latest.
View
82 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()
View
16 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
<http://www.kegel.com/c10k.html>`_.)
@@ -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>`_
@@ -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
@@ -134,4 +137,3 @@ Commons 3.0 <http://creativecommons.org/licenses/by/3.0/>`_.
:hidden:
documentation
-
View
4 website/static/sphinx.css
@@ -64,4 +64,8 @@ div.related, div.sphinxsidebar {
div.section {
max-width: 850px;
+}
+
+a.reference.internal em {
+ font-style: normal;
}
Something went wrong with that request. Please try again.