quart-httpauth
Basic, Digest and Token (Bearer) HTTP authentication for Quart routes — an async-native port of Flask-HTTPAuth.
The public API mirrors Flask-HTTPAuth: class names, constructor arguments,
decorator names, and callback contracts are preserved. Existing Flask-HTTPAuth
code transfers by switching flask imports to quart and flask_httpauth to
quart_httpauth. The one intentional change is that the request pipeline and
every callback are awaited — your verify/role/error callbacks may be written as
either def or async def.
Installation
pip install quart-httpauth
The distribution name is quart-httpauth; the import name is quart_httpauth.
Quickstart — Basic auth
from quart import Quart
from quart_httpauth import HTTPBasicAuth
from werkzeug.security import check_password_hash, generate_password_hash
app = Quart(__name__)
auth = HTTPBasicAuth()
users = {
"susan": generate_password_hash("hunter2"),
}
@auth.verify_password
async def verify_password(username, password):
if username in users and check_password_hash(users[username], password):
return username
@app.route("/")
@auth.login_required
async def index():
return f"Hello, {auth.current_user()}!"
Token (Bearer) auth
from quart import Quart
from quart_httpauth import HTTPTokenAuth
app = Quart(__name__)
auth = HTTPTokenAuth(scheme="Bearer")
tokens = {"secret-token-1": "john"}
@auth.verify_token
async def verify_token(token):
return tokens.get(token)
@app.route("/")
@auth.login_required
async def index():
return f"Hello, {auth.current_user()}!"
A custom header works too: HTTPTokenAuth(header="X-API-Key") — there the entire
header value is treated as the token with no scheme prefix.
Roles and optional auth
@auth.get_user_roles
async def get_user_roles(user):
return user.roles
@app.route("/admin")
@auth.login_required(role="admin")
async def admin():
return "for admins only"
@app.route("/maybe")
@auth.login_required(optional=True)
async def maybe():
user = auth.current_user()
return f"Hello, {user or 'anonymous'}!"
Multiple schemes on one route
from quart_httpauth import HTTPBasicAuth, HTTPTokenAuth, MultiAuth
basic = HTTPBasicAuth()
token = HTTPTokenAuth()
multi = MultiAuth(basic, token) # HTTPMultiAuth is an alias
@app.route("/")
@multi.login_required
async def index():
return f"Hello, {multi.current_user()}!"
See examples/ for runnable apps.
Differences from Flask-HTTPAuth
- The deprecated
hash_passwordcallback, theusername()accessor, and the legacyget_password-as-Basic-credential path are not ported. Useverify_passwordfor Basic auth.get_passwordis retained forHTTPDigestAuth, where it is the primary, non-deprecated mechanism. - The per-request user is stored on
g.quart_httpauth_user.
License
MIT. Ported from Flask-HTTPAuth (also MIT) by Miguel Grinberg.
Metadata
Release files for quart-httpauth 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| quart_httpauth-0.0.1.tar.gz | 129.6 kB | Without provenance | Details for quart_httpauth-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| quart_httpauth-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for quart_httpauth-0.0.1-py3-none-any.whl |
Total release size: 139.8 kB
Release files / quart_httpauth-0.0.1.tar.gz
| Download URL | quart_httpauth-0.0.1.tar.gz |
|---|---|
| Size | 129.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d577bc549d8de72ac2704b78086e045b31bf3efcf581b5a9090e3417c2654835
|
|
BLAKE2b-256 checksum How to use checksums |
8c9cce53392ee7e1f30e7707c2d2db65281c356e49f99cee3db27ff8d0dcbf67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / quart_httpauth-0.0.1-py3-none-any.whl
| Download URL | quart_httpauth-0.0.1-py3-none-any.whl |
|---|---|
| Size | 10.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b4c2e15fdf18e81a6d6b806329af350f11adecdf455b00fd8a1bc0beaca1fca5
|
|
BLAKE2b-256 checksum How to use checksums |
096d869bff4b958600d3c572847f404e2c84ad539240408b69e447e0fa34d1be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for quart-httpauth 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.