Skip to main content

HTTP authentication for Flask routes

Project description


Build status codecov

Simple extension that provides Basic and Digest HTTP authentication for Flask routes.


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 import generate_password_hash, check_password_hash

app = Flask(__name__)
auth = HTTPBasicAuth()

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

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

def index():
    return "Hello, %s!" % auth.current_user()

if __name__ == '__main__':

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"

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

def index():
    return "Hello, %s!" % auth.username()

if __name__ == '__main__':


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

Flask-HTTPAuth-4.8.0.tar.gz (230.3 kB view hashes)

Uploaded Source

Built Distribution

Flask_HTTPAuth-4.8.0-py3-none-any.whl (7.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page