Skip to main content

Digest and basic authentication for tornado

Project description

Latest version released on PyPi Apache License, Version 2.0.

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

tornado-http-auth-1.1.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tornado_http_auth-1.1.1-py2.py3-none-any.whl (6.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file tornado-http-auth-1.1.1.tar.gz.

File metadata

File hashes

Hashes for tornado-http-auth-1.1.1.tar.gz
Algorithm Hash digest
SHA256 1d6cc051ebf93807138367b3b2f2822c266edeed8bcc9bd2f22526a0802bcc43
MD5 d7a3a5d3a6fe111e9e15a77e56652ef9
BLAKE2b-256 1e051021c5d235b610b8fb3e16b9c4b91a70ee93c7e51916cc78cfb31ab38385

See more details on using hashes here.

File details

Details for the file tornado_http_auth-1.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for tornado_http_auth-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2d8a4f49c4a8e99460942dd6168b455dd9f722fdc78d445630310ddf524c664a
MD5 0ccbf439b969efc6927aef4fb4fdbb20
BLAKE2b-256 9b6a2a3c3669e7a45eda461a4426bd14620e175779e9829a8b3e4a4f258bf0fe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page