Skip to content

Quart-HTTPAuth: Authentication for Quart, Inspired by Flask-HTTPAuth

License

Notifications You must be signed in to change notification settings

collinsmarra/Quart-HTTPAuth

Repository files navigation

Quart-HTTPAuth

Build status codecov

Quart-HTTPAuth: An Authentication Extension for Quart

Welcome to Quart-HTTPAuth, a simple extension that provides Basic, Digest, and Token HTTP authentication support to Quart. This project is a modified version of Flask-HTTPAuth, specifically for use with Quart.

I developed this extension because I wanted to use Quart and Flask-HTTPAuth in a single project, but encountered issues when using Quart.quart_flask_patch with Flask-HTTPAuth after upgrading to Quart=='0.19.0'.My existing application, which functioned well with Quart==0.18.4 and Flask-HTTPAuth, would no longer work. To avoid the hassle of migrating to a new authentication extension, I opted to create this modified version of Flask-HTTPAuth that plays seamlessly with Quart.

Features

  • Supports Basic, Digest, and Token HTTP authentication
  • Easy to use and integrate with Quart
  • Works exactly how you'd expect Flask-HTTPAuth to.

⚠️ Caution: Please exercise discretion and use Quart-HTTPAuth at your own risk.

Installation

pip install git+https://github.com/collinsmarra/Quart-HTTPAuth.git

Basic authentication example

from quart import Quart
from quart_httpauth import HTTPBasicAuth
from werkzeug.security import generate_password_hash, check_password_hash

app = Quart(__name__)
auth = HTTPBasicAuth()

users = {
    "john": generate_password_hash("hello"),
    "susan": generate_password_hash("bye")
}

@auth.verify_password
def verify_password(username, password):
    if username in users and \
            check_password_hash(users.get(username), password):
        return username

@app.route('/')
@auth.login_required
async def index():
    return "Hello, %s!" % auth.current_user()

if __name__ == '__main__':
    app.run()

Digest authentication example

from quart import Quart
from quart_httpauth import HTTPDigestAuth

app = Quart(__name__)
app.config['SECRET_KEY'] = 'secret key here'
auth = HTTPDigestAuth()

users = {
    "john": "hello",
    "susan": "bye"
}

@auth.get_password
def get_pw(username):
    if username in users:
        return users.get(username)
    return None

@app.route('/')
@auth.login_required
async def index():
    return "Hello, %s!" % auth.username()

if __name__ == '__main__':
    app.run()

About

Quart-HTTPAuth: Authentication for Quart, Inspired by Flask-HTTPAuth

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages