Quart-Auth
==========
|Build Status| |docs| |pypi| |python| |license|
Quart-Auth is an extension for `Quart
<https://gitlab.com/pgjones/quart>`_ to provide for secure cookie
authentication (session management). It allows for a session to be
logged in, authenticated and logged out.
Usage
-----
To use Quart-Auth with a Quart app you have to create an QuartAuth and
initialise it with the application,
.. code-block:: python
app = Quart(__name__)
QuartAuth(app)
or via the factory pattern,
.. code-block:: python
auth_manager = QuartAuth()
def create_app():
app = Quart(__name__)
auth_manager.init_app(app)
return app
In addition you will need to configure Quart-Auth, which defaults to
the most secure. At a minimum you will need to set secret key,
.. code-block:: python
app.secret_key = "secret key" # Do not use this key
which you can generate via,
.. code-block:: python
>>> import secrets
>>> secrets.token_urlsafe(16)
Tou may also need to disable secure cookies to use in development, see
configuration below.
With QuartAuth initialised you can use the ``login_required``
function to decorate routes that should only be accessed by
authenticated users,
.. code-block:: python
from quart_auth import login_required
@app.route("/")
@login_required
async def restricted_route():
...
If no user is logged in, an ``Unauthorized`` exception is raised. To catch it,
install an error handler,
.. code-block:: python
@app.errorhandler(Unauthorized)
async def redirect_to_login(*_: Exception) -> ResponseReturnValue:
return redirect(url_for("login"))
You can also use the ``login_user``, and ``logout_user`` functions to
start and end sessions for a specific ``AuthenticatedUser`` instance,
.. code-block:: python
from quart_auth import AuthUser, login_user, logout_user
@app.route("/login")
async def login():
# Check Credentials here, e.g. username & password.
...
# We'll assume the user has an identifying ID equal to 2
login_user(AuthUser(2))
...
@app.route("/logout")
async def logout():
logout_user()
...
The user (authenticated or not) is available via the global
``current_user`` including within templates,
.. code-block:: python
from quart import render_template_string
from quart_auth import current_user
@app.route("/")
async def user():
return await render_template_string("{{ current_user.is_authenticated }}")
Contributing
------------
Quart-Auth is developed on `GitHub
<https://github.com/pgjones/quart-auth>`_. You are very welcome to
open `issues <https://github.com/pgjones/quart-auth/issues>`_ or
propose `pull requests
<https://github.com/pgjones/quart-auth/pulls>`_.
Testing
~~~~~~~
The best way to test Quart-Auth is with Tox,
.. code-block:: console
$ pip install tox
$ tox
this will check the code style and run the tests.
Help
----
The Quart-Auth `documentation
<https://quart-auth.readthedocs.io>`_ is the best places to
start, after that try searching `stack overflow
<https://stackoverflow.com/questions/tagged/quart>`_ or ask for help
`on gitter <https://gitter.im/python-quart/lobby>`_. If you still
can't find an answer please `open an issue
<https://github.com/pgjones/quart-auth/issues>`_.
.. |Build Status| image:: https://github.com/pgjones/quart-auth/actions/workflows/ci.yml/badge.svg
:target: https://github.com/pgjones/quart-auth/commits/main
.. |docs| image:: https://img.shields.io/badge/docs-passing-brightgreen.svg
:target: https://quart-auth.readthedocs.io
.. |pypi| image:: https://img.shields.io/pypi/v/quart-auth.svg
:target: https://pypi.python.org/pypi/Quart-Auth/
.. |python| image:: https://img.shields.io/pypi/pyversions/quart-auth.svg
:target: https://pypi.python.org/pypi/Quart-Auth/
.. |license| image:: https://img.shields.io/badge/license-MIT-blue.svg
:target: https://github.com/pgjones/quart-auth/blob/main/LICENSE
Raw data
{
"_id": null,
"home_page": "https://github.com/pgjones/quart-auth/",
"name": "quart-auth",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": "pgjones",
"author_email": "philip.graham.jones@googlemail.com",
"download_url": "https://files.pythonhosted.org/packages/af/dd/9f93c9419f50fe0fe3ee00a9b140f364cf2be73de5b3fac332034597c871/quart_auth-0.10.1.tar.gz",
"platform": null,
"description": "Quart-Auth\n==========\n\n|Build Status| |docs| |pypi| |python| |license|\n\nQuart-Auth is an extension for `Quart\n<https://gitlab.com/pgjones/quart>`_ to provide for secure cookie\nauthentication (session management). It allows for a session to be\nlogged in, authenticated and logged out.\n\nUsage\n-----\n\nTo use Quart-Auth with a Quart app you have to create an QuartAuth and\ninitialise it with the application,\n\n.. code-block:: python\n\n app = Quart(__name__)\n QuartAuth(app)\n\nor via the factory pattern,\n\n.. code-block:: python\n\n auth_manager = QuartAuth()\n\n def create_app():\n app = Quart(__name__)\n auth_manager.init_app(app)\n return app\n\nIn addition you will need to configure Quart-Auth, which defaults to\nthe most secure. At a minimum you will need to set secret key,\n\n.. code-block:: python\n\n app.secret_key = \"secret key\" # Do not use this key\n\nwhich you can generate via,\n\n.. code-block:: python\n\n >>> import secrets\n >>> secrets.token_urlsafe(16)\n\nTou may also need to disable secure cookies to use in development, see\nconfiguration below.\n\nWith QuartAuth initialised you can use the ``login_required``\nfunction to decorate routes that should only be accessed by\nauthenticated users,\n\n.. code-block:: python\n\n from quart_auth import login_required\n\n @app.route(\"/\")\n @login_required\n async def restricted_route():\n ...\n\nIf no user is logged in, an ``Unauthorized`` exception is raised. To catch it,\ninstall an error handler,\n\n.. code-block:: python\n\n @app.errorhandler(Unauthorized)\n async def redirect_to_login(*_: Exception) -> ResponseReturnValue:\n return redirect(url_for(\"login\"))\n\nYou can also use the ``login_user``, and ``logout_user`` functions to\nstart and end sessions for a specific ``AuthenticatedUser`` instance,\n\n.. code-block:: python\n\n from quart_auth import AuthUser, login_user, logout_user\n\n @app.route(\"/login\")\n async def login():\n # Check Credentials here, e.g. username & password.\n ...\n # We'll assume the user has an identifying ID equal to 2\n login_user(AuthUser(2))\n ...\n\n @app.route(\"/logout\")\n async def logout():\n logout_user()\n ...\n\nThe user (authenticated or not) is available via the global\n``current_user`` including within templates,\n\n.. code-block:: python\n\n from quart import render_template_string\n from quart_auth import current_user\n\n @app.route(\"/\")\n async def user():\n return await render_template_string(\"{{ current_user.is_authenticated }}\")\n\nContributing\n------------\n\nQuart-Auth is developed on `GitHub\n<https://github.com/pgjones/quart-auth>`_. You are very welcome to\nopen `issues <https://github.com/pgjones/quart-auth/issues>`_ or\npropose `pull requests\n<https://github.com/pgjones/quart-auth/pulls>`_.\n\nTesting\n~~~~~~~\n\nThe best way to test Quart-Auth is with Tox,\n\n.. code-block:: console\n\n $ pip install tox\n $ tox\n\nthis will check the code style and run the tests.\n\nHelp\n----\n\nThe Quart-Auth `documentation\n<https://quart-auth.readthedocs.io>`_ is the best places to\nstart, after that try searching `stack overflow\n<https://stackoverflow.com/questions/tagged/quart>`_ or ask for help\n`on gitter <https://gitter.im/python-quart/lobby>`_. If you still\ncan't find an answer please `open an issue\n<https://github.com/pgjones/quart-auth/issues>`_.\n\n\n.. |Build Status| image:: https://github.com/pgjones/quart-auth/actions/workflows/ci.yml/badge.svg\n :target: https://github.com/pgjones/quart-auth/commits/main\n\n.. |docs| image:: https://img.shields.io/badge/docs-passing-brightgreen.svg\n :target: https://quart-auth.readthedocs.io\n\n.. |pypi| image:: https://img.shields.io/pypi/v/quart-auth.svg\n :target: https://pypi.python.org/pypi/Quart-Auth/\n\n.. |python| image:: https://img.shields.io/pypi/pyversions/quart-auth.svg\n :target: https://pypi.python.org/pypi/Quart-Auth/\n\n.. |license| image:: https://img.shields.io/badge/license-MIT-blue.svg\n :target: https://github.com/pgjones/quart-auth/blob/main/LICENSE\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Quart extension to provide secure cookie authentication",
"version": "0.10.1",
"project_urls": {
"Homepage": "https://github.com/pgjones/quart-auth/",
"Repository": "https://github.com/pgjones/quart-auth/"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "62f7ea7eb12f2461de11ade546353546f386c27ce1b99a8ec247625d2c73fe91",
"md5": "2ef2fcb982ac15653a1c2ebdb7e13434",
"sha256": "72a124c5bf6313e53a456034f477f317c382b677beab4fa91279fb5866db946d"
},
"downloads": -1,
"filename": "quart_auth-0.10.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "2ef2fcb982ac15653a1c2ebdb7e13434",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 9646,
"upload_time": "2024-05-18T21:25:05",
"upload_time_iso_8601": "2024-05-18T21:25:05.015466Z",
"url": "https://files.pythonhosted.org/packages/62/f7/ea7eb12f2461de11ade546353546f386c27ce1b99a8ec247625d2c73fe91/quart_auth-0.10.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "afdd9f93c9419f50fe0fe3ee00a9b140f364cf2be73de5b3fac332034597c871",
"md5": "cc2c054c6b3e76e8963d59b5877a5842",
"sha256": "d895d12c0818645a5828f6200b0cbbb8ad4ae3e5dcdc00a3977c105b4294f39a"
},
"downloads": -1,
"filename": "quart_auth-0.10.1.tar.gz",
"has_sig": false,
"md5_digest": "cc2c054c6b3e76e8963d59b5877a5842",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 9255,
"upload_time": "2024-05-18T21:25:06",
"upload_time_iso_8601": "2024-05-18T21:25:06.690968Z",
"url": "https://files.pythonhosted.org/packages/af/dd/9f93c9419f50fe0fe3ee00a9b140f364cf2be73de5b3fac332034597c871/quart_auth-0.10.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-18 21:25:06",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "pgjones",
"github_project": "quart-auth",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "quart-auth"
}