HTTP authentication for Flask routes
Project description
Flask-HTTPAuth
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
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
Project details
Release history Release notifications | RSS feed
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.5.0.tar.gz
(36.0 kB
view details)
Built Distribution
File details
Details for the file Flask-HTTPAuth-4.5.0.tar.gz
.
File metadata
- Download URL: Flask-HTTPAuth-4.5.0.tar.gz
- Upload date:
- Size: 36.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 395040fda2854df800d15e84bc4a81a5f32f1d4a5e91eee554936f36f330aa29 |
|
MD5 | 0044a8372f7436f190a0b5e0747639ed |
|
BLAKE2b-256 | d9c8b4d278366fcb1c25d2b8552a5f4764961af46a794135499079b6ff9f4895 |
File details
Details for the file Flask_HTTPAuth-4.5.0-py3-none-any.whl
.
File metadata
- Download URL: Flask_HTTPAuth-4.5.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e16067ba3378ea366edf8de4b9d55f38c0a0cbddefcc0f777a54b3fce1d99392 |
|
MD5 | 8870d2a5c25268d2c3ca2a93998c3440 |
|
BLAKE2b-256 | 3891dbdb73482b566ea16df7851140f224ffad57dbb8ea6021cbaedb7eb2072d |