Simple extension that provides Basic, Digest and Token HTTP authentication for Flask routes
Find a file
2026-05-14 20:37:50 +01:00
.github/workflows tox configuration 2026-05-14 20:37:50 +01:00
docs Restore warning about Digest server-side session requirement (#170) 2026-04-07 09:36:16 +01:00
examples Replace itsdangerous with pyjwt in examples (Fixes #157) 2023-02-11 11:54:52 +00:00
src Restore warning about Digest server-side session requirement (#170) 2026-04-07 09:36:16 +01:00
tests Do not accept empty tokens 2026-03-28 19:03:45 +00:00
.gitignore Revised documentation 2026-03-11 00:24:31 +00:00
.readthedocs.yaml Read the docs configuration 2026-03-11 00:31:01 +00:00
.travis.yml Remove python 3.5 and add python 3.9 to build 2020-11-16 10:39:39 +00:00
AUTHORS Ignore authentication headers for OPTIONS 2014-04-07 17:56:10 -03:00
CHANGES.md Release 4.8.1 2026-03-28 19:39:25 +00:00
LICENSE changed auth.username to auth.username() 2013-09-26 09:13:53 -07:00
MANIFEST.in Migrate Python package metadata to pyproject.toml 2023-10-15 13:03:34 +01:00
pyproject.toml Version 4.8.2.dev0 2026-03-28 19:48:38 +00:00
README.md Fix change log link in readme 2026-03-11 00:54:22 +00:00
tox.ini tox configuration 2026-05-14 20:37:50 +01:00

Flask-HTTPAuth

Build status codecov

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