Skip to content
Simple extension that provides Basic, Digest and Token HTTP authentication for Flask routes
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Edited and changed the usage of JWT, because in fact the code and doc… Feb 5, 2019
examples Edited and changed the usage of JWT, because in fact the code and doc… Feb 5, 2019
tests Validate authorization header in multi auth Jan 30, 2017
.gitignore Initial commit May 18, 2013
.travis.yml travis build fix for py36 May 16, 2018
AUTHORS Ignore authentication headers for OPTIONS Apr 7, 2014
CHANGELOG.md
LICENSE changed auth.username to auth.username() Sep 26, 2013
MANIFEST.in
README.md Update PyPI link in README (#71) Jun 17, 2018
flask_httpauth.py Release 3.2.4 Jun 17, 2018
setup.py add __version__ to package Sep 4, 2016
tox.ini Validate authorization header in multi auth Jan 30, 2017

README.md

Flask-HTTPAuth

Build Status

Simple extension that provides Basic and Digest 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

app = Flask(__name__)
auth = HTTPBasicAuth()

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()

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

You can’t perform that action at this time.