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.0.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.0-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.0.tar.gz.

File metadata

File hashes

Hashes for tornado-http-auth-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c5ba0835e783f2b9ccc1ccd86235913f1830a0893f7672888a448b791a7ed97e
MD5 ead645af4311bf1d33e73e2b067ef0c1
BLAKE2b-256 b0741f9d8f26a9741b57a1789278ce29dc8c4cb21179b9a771981e418a90ad95

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for tornado_http_auth-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2de9b76c9834eb47c4ca4f94e10735c92367c5db485d44a79529b7f48c75f046
MD5 5d76cffe4b17fc20fe5eefa4925ae2a6
BLAKE2b-256 afcd5b98fb738ce2399b4237a721fcd135026ddfd725deda5fd4616a409519c3

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