GithubHelp home page GithubHelp logo

tornado-http-auth's Introduction

tornado-http-auth

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-http-auth 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.

tornado-http-auth's People

Contributors

adrianrv avatar gvalkov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

tornado-http-auth's Issues

Example on README has a problem

Running the example on README produces the following error:
File "test_http_auth.py", line 17, in prepare
self.get_authenticated_user(realm='Protected', auth_func=credentials.get)
TypeError: get_authenticated_user() got an unexpected keyword argument 'auth_func'

PAM-based authentication ?

I had a look at the code while attempting to setup a tornado server with http auth based on PAM and this :

challenge = check_credentials_func(username)
        if not challenge:
            raise self.SendChallenge()

        if challenge == password:

makes it somewhat incompatible with PAM authentication, as far as I can tell...

For reference : https://github.com/FirefighterBlu3/python-pam/blob/master/pam.py provides an authenticate(username, password) function where one passes the user and the password at once, and the return value (after some waiting time) determine if we are logged in or not.

Any hint/ideas on how to improve this ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.