Digest and basic authentication for tornado
Project description
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.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tornado-http-auth-1.1.1.tar.gz.
File metadata
- Download URL: tornado-http-auth-1.1.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d6cc051ebf93807138367b3b2f2822c266edeed8bcc9bd2f22526a0802bcc43
|
|
| MD5 |
d7a3a5d3a6fe111e9e15a77e56652ef9
|
|
| BLAKE2b-256 |
1e051021c5d235b610b8fb3e16b9c4b91a70ee93c7e51916cc78cfb31ab38385
|
File details
Details for the file tornado_http_auth-1.1.1-py2.py3-none-any.whl.
File metadata
- Download URL: tornado_http_auth-1.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d8a4f49c4a8e99460942dd6168b455dd9f722fdc78d445630310ddf524c664a
|
|
| MD5 |
0ccbf439b969efc6927aef4fb4fdbb20
|
|
| BLAKE2b-256 |
9b6a2a3c3669e7a45eda461a4426bd14620e175779e9829a8b3e4a4f258bf0fe
|