Flask-HTTPAuth
Simple extension that provides Basic, Digest and Token HTTP authentication for Flask routes.
Installation
The easiest way to install this is through pip.
pip install Flask-HTTPAuth
Basic authentication example
from flask import Flask
from flask_httpauth import HTTPBasicAuth
from werkzeug.security import generate_password_hash, check_password_hash
app = Flask(__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
def index():
return "Hello, %s!" % auth.current_user()
if __name__ == '__main__':
app.run()
Note: See the documentation for more complex examples that involve password hashing and custom verification callbacks.
Digest authentication example
from flask import Flask
from flask_httpauth import HTTPDigestAuth
app = Flask(__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
def index():
return "Hello, %s!" % auth.username()
if __name__ == '__main__':
app.run()
Resources
Release files for Flask-HTTPAuth 4.8.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 | |
|---|---|---|---|
| flask_httpauth-4.8.1.tar.gz | 39.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flask_httpauth-4.8.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 48.6 kB
Release files / flask_httpauth-4.8.1.tar.gz
| Download URL | flask_httpauth-4.8.1.tar.gz |
|---|---|
| Size | 39.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
88499b22f1353893743c3cd68f2ca561c4ad9ef75cd6bcc7f621161cd0e80744
|
|
BLAKE2b-256 checksum How to use checksums |
ecf46957215e827021eeb7d8de9f59b1864d73933b04851e59272708cb6e5d2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / flask_httpauth-4.8.1-py3-none-any.whl
| Download URL | flask_httpauth-4.8.1-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0080393d70e12327781f7509115175ec5e47209816489a620d4fd39e20cea2e8
|
|
BLAKE2b-256 checksum How to use checksums |
72da624c87bf6c13107ceab8ee23815d9468e47d89c7480c1dc9af39b08eb290
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|