Metadata-Version: 2.1
Name: zgw-auth-backend
Version: 1.0.3
Summary: A Django REST framework authentication class for the ZGW API authentication pattern.
Home-page: https://github.com/maykinmedia/zgw-auth-backend
Author: Maykin Media
Author-email: support@maykinmedia.nl
License: MIT
Keywords: zgw,vng,apis,drf
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: Django
Classifier: Framework :: Django :: 2.2
Classifier: Framework :: Django :: 3.0
Classifier: Framework :: Django :: 3.1
Classifier: Intended Audience :: Developers
Classifier: Operating System :: Unix
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: django
Requires-Dist: djangorestframework
Requires-Dist: pyjwt
Provides-Extra: coverage
Requires-Dist: pytest-cov ; extra == 'coverage'
Provides-Extra: docs
Requires-Dist: sphinx ; extra == 'docs'
Requires-Dist: sphinx-rtd-theme ; extra == 'docs'
Provides-Extra: pep8
Requires-Dist: flake8 ; extra == 'pep8'
Provides-Extra: release
Requires-Dist: bump2version ; extra == 'release'
Requires-Dist: twine ; extra == 'release'
Provides-Extra: tests
Requires-Dist: pytest ; extra == 'tests'
Requires-Dist: pytest-django ; extra == 'tests'
Requires-Dist: tox ; extra == 'tests'
Requires-Dist: isort ; extra == 'tests'
Requires-Dist: gemma-zds-client (>=1.0.0) ; extra == 'tests'
Requires-Dist: black ; extra == 'tests'

Welcome to zgw-auth-backend's documentation!
============================================

:Version: 1.0.3
:Source: https://github.com/maykinmedia/zgw-auth-backend
:Keywords: zgw, vng, apis, drf
:PythonVersion: 3.8

|build-status| |coverage| |linting| |black|

|python-versions| |django-versions| |pypi-version|

A Django REST framework authentication class for the ZGW API authentication pattern.

The ZGW Auth JWT includes claims for ``user_id`` and ``user_representation``. This
information can be used in your API to authenticate the actual end-user, even when
using gateway APIs.

.. contents::

.. section-numbering::

Features
========

* Authenticates the end-user based on the ``user_id`` JWT claim
* Follows the auth spec for "API's voor zaakgericht werken"

Installation
============

Requirements
------------

* Python 3.7 or higher
* setuptools 30.3.0 or above
* Django 2.2 or newer


Install
-------

.. code-block:: bash

    pip install zgw-auth-backend

Add it to your installed apps:

.. code-block:: py

    INSTALLED_APPS += ["zgw_auth_backend"]

Migrate:

.. code-block:: bash

    python manage.py migrate

Optionally, you can add it to DRFs default backends:

.. code-block:: py

    REST_FRAMEWORK = {
        "DEFAULT_AUTHENTICATION_CLASSES": [
            ...,
            "zgw_auth_backend.authentication.ZGWAuthentication",
            ...,
        ],
    }


Usage
=====

Specify the authentication class on your view(s):

.. code-block:: py

    from rest_framework import views
    from zgw_auth_backend.authentication import ZGWAuthentication

    class MyView(APIView):
        authentication_classes = (ZGWAuthentication,)


1. Add the client credentials in the admin (client ID + secret)
2. Generate a ZGW auth JWT with the ``user_id`` claim, using the credentials from step 1
3. Make an API call to the endpoint, including the ``Authorization: Bearer <jwt>`` header
4. Verify that the user with ``user_id`` username is created if it didn't exist yet, or
   if it did, that ``request.user`` is now this user.


.. |build-status| image:: https://github.com/maykinmedia/zgw-auth-backend/workflows/Run%20CI/badge.svg
    :target: https://github.com/maykinmedia/zgw-auth-backend/actions?query=workflow%3A%22Run+CI%22
    :alt: Run CI

.. |linting| image:: https://github.com/maykinmedia/zgw-auth-backend/workflows/Code%20quality%20checks/badge.svg
    :target: https://github.com/maykinmedia/zgw-auth-backend/actions?query=workflow%3A%22Code+quality+checks%22
    :alt: Code linting

.. |coverage| image:: https://codecov.io/gh/maykinmedia/zgw-auth-backend/branch/master/graph/badge.svg
    :target: https://codecov.io/gh/maykinmedia/zgw-auth-backend
    :alt: Coverage status

.. |black| image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black

.. |python-versions| image:: https://img.shields.io/pypi/pyversions/zgw-auth-backend.svg

.. |django-versions| image:: https://img.shields.io/pypi/djversions/zgw-auth-backend.svg

.. |pypi-version| image:: https://img.shields.io/pypi/v/zgw-auth-backend.svg
    :target: https://pypi.org/project/zgw-auth-backend/


