quart-auth


Namequart-auth JSON
Version 0.11.0 PyPI version JSON
download
home_pageNone
SummaryA Quart extension to provide secure cookie authentication
upload_time2024-12-26 21:47:46
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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)

You 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": null,
    "name": "quart-auth",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "pgjones <philip.graham.jones@googlemail.com>",
    "download_url": "https://files.pythonhosted.org/packages/45/8d/d965905118fe612e7520f8a1014e4988842d8ed9fd68de4471999f7d968b/quart_auth-0.11.0.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\nYou 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",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A Quart extension to provide secure cookie authentication",
    "version": "0.11.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cfa38ca9235569f39e471a9a319ba1665a27cb9cea8c48c688966460db67d48f",
                "md5": "08834256f340d7f647d8fba83697f151",
                "sha256": "dd342ea39475a9b32b79d83e2b6820ddaa358e77f01dedbba47d50529f2c8c74"
            },
            "downloads": -1,
            "filename": "quart_auth-0.11.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "08834256f340d7f647d8fba83697f151",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 9958,
            "upload_time": "2024-12-26T21:47:44",
            "upload_time_iso_8601": "2024-12-26T21:47:44.717966Z",
            "url": "https://files.pythonhosted.org/packages/cf/a3/8ca9235569f39e471a9a319ba1665a27cb9cea8c48c688966460db67d48f/quart_auth-0.11.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "458dd965905118fe612e7520f8a1014e4988842d8ed9fd68de4471999f7d968b",
                "md5": "3acb385843284aef4f921b66fbf8660c",
                "sha256": "7703df693d795b3ec43a634efe4118c6adbddd98e7b8195008ca6def6d45cb47"
            },
            "downloads": -1,
            "filename": "quart_auth-0.11.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3acb385843284aef4f921b66fbf8660c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 11122,
            "upload_time": "2024-12-26T21:47:46",
            "upload_time_iso_8601": "2024-12-26T21:47:46.074468Z",
            "url": "https://files.pythonhosted.org/packages/45/8d/d965905118fe612e7520f8a1014e4988842d8ed9fd68de4471999f7d968b/quart_auth-0.11.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-26 21:47:46",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "quart-auth"
}
        
Elapsed time: 0.95462s