Digest and basic authentication for the Tornado web framework. Based on code and ideas from Twisted’s cred.
Installation
The latest stable version of tornado-ansi-markup can be installed from pypi:
$ pip install tornado-http-auth
Usage
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
License
This project is released under the terms of the Apache License, Version 2.0.
Metadata
Release files for tornado-http-auth 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tornado-http-auth-1.1.1.tar.gz | 4.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| tornado_http_auth-1.1.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 10.9 kB
Release files / tornado-http-auth-1.1.1.tar.gz
| Download URL | tornado-http-auth-1.1.1.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1d6cc051ebf93807138367b3b2f2822c266edeed8bcc9bd2f22526a0802bcc43
|
|
BLAKE2b-256 checksum How to use checksums |
1e051021c5d235b610b8fb3e16b9c4b91a70ee93c7e51916cc78cfb31ab38385
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / tornado_http_auth-1.1.1-py2.py3-none-any.whl
| Download URL | tornado_http_auth-1.1.1-py2.py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
2d8a4f49c4a8e99460942dd6168b455dd9f722fdc78d445630310ddf524c664a
|
|
BLAKE2b-256 checksum How to use checksums |
9b6a2a3c3669e7a45eda461a4426bd14620e175779e9829a8b3e4a4f258bf0fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |