Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/miguelgrinberg/flask-httpauth
Simple extension that provides Basic, Digest and Token HTTP authentication for Flask routes
https://github.com/miguelgrinberg/flask-httpauth
authentication flask flask-httpauth python security tokens
Last synced: 19 days ago
JSON representation
Simple extension that provides Basic, Digest and Token HTTP authentication for Flask routes
- Host: GitHub
- URL: https://github.com/miguelgrinberg/flask-httpauth
- Owner: miguelgrinberg
- License: mit
- Created: 2013-05-18T05:10:52.000Z (over 11 years ago)
- Default Branch: main
- Last Pushed: 2024-04-27T23:25:37.000Z (6 months ago)
- Last Synced: 2024-05-02T04:53:10.700Z (6 months ago)
- Topics: authentication, flask, flask-httpauth, python, security, tokens
- Language: Python
- Homepage:
- Size: 265 KB
- Stars: 1,251
- Watchers: 23
- Forks: 223
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
- awesome-python-security - Flask-HTTPAuth - Simple extension that provides Basic, Digest and Token HTTP authentication for Flask routes. (Web Framework Hardening)
README
Flask-HTTPAuth
==============[![Build status](https://github.com/miguelgrinberg/Flask-HTTPAuth/workflows/build/badge.svg)](https://github.com/miguelgrinberg/Flask-HTTPAuth/actions) [![codecov](https://codecov.io/gh/miguelgrinberg/Flask-HTTPAuth/branch/master/graph/badge.svg?token=KeU2002DHo)](https://codecov.io/gh/miguelgrinberg/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
----------------------------```python
from flask import Flask
from flask_httpauth import HTTPBasicAuth
from werkzeug.security import generate_password_hash, check_password_hashapp = 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](https://flask-httpauth.readthedocs.io/) for more complex examples that involve password hashing and custom verification callbacks.
Digest authentication example
-----------------------------```python
from flask import Flask
from flask_httpauth import HTTPDigestAuthapp = 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
---------- [Documentation](http://flask-httpauth.readthedocs.io/en/latest/)
- [PyPI](https://pypi.org/project/Flask-HTTPAuth)
- [Change log](https://github.com/miguelgrinberg/Flask-HTTPAuth/blob/master/CHANGES.md)