tornado的摘要和基本身份验证
项目描述
Digest and basic authentication for the Tornado web framework. Based on code and ideas from Twisted’s cred.
安装
tornado-ansi-markup的最新稳定版本可以从pypi安装
$ pip install tornado-http-auth
用法
import tornado.ioloop
from tornado.web import RequestHandler, Application
from tornado_http_auth import DigestAuthMixin, BasicAuthMixin, auth_required
credentials = {'user1': 'pass1'}
# Example 1 (using decorator).
class MainHandler(DigestAuthMixin, RequestHandler):
@auth_required(realm='Protected', auth_func=credentials.get)
def get(self):
self.write('Hello %s' % self._current_user)
# Example 2 (using prepare and get_authentciated_user).
class MainHandler(BasicAuthMixin, RequestHandler):
def prepare(self):
self.get_authenticated_user(check_credentials_func=credentials.get, realm='Protected')
def get(self):
self.write('Hello %s' % self._current_user)
app = Application([
(r'/', MainHandler),
])
app.listen(8888)
tornado.ioloop.IOLoop.current().start()
# curl --user user1:pass1 -v http://localhost:8888 -> 200 OK
# curl --user user2:pass2 -v http://localhost:8888 -> 401 Unauthorized
# Remove or comment second class
# curl --digest --user user1:pass1 -v http://localhost:8888 -> 200 OK
# curl --digest --user user2:pass2 -v http://localhost:8888 -> 401 Unauthorized
许可证
本项目根据Apache许可证,版本2.0发布。
项目详情
关闭
哈希值 for tornado_http_auth-1.1.1-py2.py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 2d8a4f49c4a8e99460942dd6168b455dd9f722fdc78d445630310ddf524c664a |
|
MD5 | 0ccbf439b969efc6927aef4fb4fdbb20 |
|
BLAKE2b-256 | 9b6a2a3c3669e7a45eda461a4426bd14620e175779e9829a8b3e4a4f258bf0fe |