Flask-HTTPAuth


NameFlask-HTTPAuth JSON
Version 4.8.0 PyPI version JSON
download
home_pagehttps://github.com/miguelgrinberg/flask-httpauth
SummaryHTTP authentication for Flask routes
upload_time2023-04-27 09:25:57
maintainer
docs_urlhttps://pythonhosted.org/Flask-HTTPAuth/
authorMiguel Grinberg
requires_python
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            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 and Digest 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_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](http://pythonhosted.org/Flask-HTTPAuth) for more complex examples that involve password hashing and custom verification callbacks.

Digest authentication example
-----------------------------

```python
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
---------

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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/miguelgrinberg/flask-httpauth",
    "name": "Flask-HTTPAuth",
    "maintainer": "",
    "docs_url": "https://pythonhosted.org/Flask-HTTPAuth/",
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Miguel Grinberg",
    "author_email": "miguel.grinberg@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/22/21/0160aa217c4df74e44a04919213f9c8af7e68551c10267b055f1e09d421c/Flask-HTTPAuth-4.8.0.tar.gz",
    "platform": null,
    "description": "Flask-HTTPAuth\n==============\n\n[![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)\n\nSimple extension that provides Basic and Digest HTTP authentication for Flask routes.\n\nInstallation\n------------\nThe easiest way to install this is through pip.\n```\npip install Flask-HTTPAuth\n```\n\nBasic authentication example\n----------------------------\n\n```python\nfrom flask import Flask\nfrom flask_httpauth import HTTPBasicAuth\nfrom werkzeug.security import generate_password_hash, check_password_hash\n\napp = Flask(__name__)\nauth = HTTPBasicAuth()\n\nusers = {\n    \"john\": generate_password_hash(\"hello\"),\n    \"susan\": generate_password_hash(\"bye\")\n}\n\n@auth.verify_password\ndef verify_password(username, password):\n    if username in users and \\\n            check_password_hash(users.get(username), password):\n        return username\n\n@app.route('/')\n@auth.login_required\ndef index():\n    return \"Hello, %s!\" % auth.current_user()\n\nif __name__ == '__main__':\n    app.run()\n```\n\nNote: See the [documentation](http://pythonhosted.org/Flask-HTTPAuth) for more complex examples that involve password hashing and custom verification callbacks.\n\nDigest authentication example\n-----------------------------\n\n```python\nfrom flask import Flask\nfrom flask_httpauth import HTTPDigestAuth\n\napp = Flask(__name__)\napp.config['SECRET_KEY'] = 'secret key here'\nauth = HTTPDigestAuth()\n\nusers = {\n    \"john\": \"hello\",\n    \"susan\": \"bye\"\n}\n\n@auth.get_password\ndef get_pw(username):\n    if username in users:\n        return users.get(username)\n    return None\n\n@app.route('/')\n@auth.login_required\ndef index():\n    return \"Hello, %s!\" % auth.username()\n\nif __name__ == '__main__':\n    app.run()\n```\n\nResources\n---------\n\n- [Documentation](http://flask-httpauth.readthedocs.io/en/latest/)\n- [PyPI](https://pypi.org/project/Flask-HTTPAuth)\n- [Change log](https://github.com/miguelgrinberg/Flask-HTTPAuth/blob/master/CHANGES.md)\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "HTTP authentication for Flask routes",
    "version": "4.8.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/miguelgrinberg/flask-httpauth/issues",
        "Homepage": "https://github.com/miguelgrinberg/flask-httpauth"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "83c4e64ace124b927cd1f29270050ee0e0ef5faad75a512c5c8d733961dda9ca",
                "md5": "1f92926f533ab63fa37245471f957edd",
                "sha256": "a58fedd09989b9975448eef04806b096a3964a7feeebc0a78831ff55685b62b0"
            },
            "downloads": -1,
            "filename": "Flask_HTTPAuth-4.8.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1f92926f533ab63fa37245471f957edd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6958,
            "upload_time": "2023-04-27T09:25:55",
            "upload_time_iso_8601": "2023-04-27T09:25:55.803337Z",
            "url": "https://files.pythonhosted.org/packages/83/c4/e64ace124b927cd1f29270050ee0e0ef5faad75a512c5c8d733961dda9ca/Flask_HTTPAuth-4.8.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "22210160aa217c4df74e44a04919213f9c8af7e68551c10267b055f1e09d421c",
                "md5": "b94141e87b866e8f1e6dab494e1f9db3",
                "sha256": "66568a05bc73942c65f1e2201ae746295816dc009edd84b482c44c758d75097a"
            },
            "downloads": -1,
            "filename": "Flask-HTTPAuth-4.8.0.tar.gz",
            "has_sig": false,
            "md5_digest": "b94141e87b866e8f1e6dab494e1f9db3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 230314,
            "upload_time": "2023-04-27T09:25:57",
            "upload_time_iso_8601": "2023-04-27T09:25:57.480176Z",
            "url": "https://files.pythonhosted.org/packages/22/21/0160aa217c4df74e44a04919213f9c8af7e68551c10267b055f1e09d421c/Flask-HTTPAuth-4.8.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-04-27 09:25:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "miguelgrinberg",
    "github_project": "flask-httpauth",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "flask-httpauth"
}
        
Elapsed time: 0.38430s