Skip to main content

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

Project description

1 Welcome to zgw-auth-backend’s documentation!

Version:

1.0.0

Source:

https://github.com/maykinmedia/zgw-auth-backend

Keywords:

zgw, vng, apis, drf

PythonVersion:

3.8

Run CI Coverage status Code 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.

2 Features

  • Authenticates the end-user based on the user_id JWT claim

  • Follows the auth spec for “API’s voor zaakgericht werken”

3 Installation

3.1 Requirements

  • Python 3.7 or higher

  • setuptools 30.3.0 or above

  • Django 2.2 or newer

3.2 Install

pip install zgw-auth-backend

Add it to your installed apps:

INSTALLED_APPS += ["zgw_auth_backend"]

Migrate:

python manage.py migrate

Optionally, you can add it to DRFs default backends:

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

4 Usage

Specify the authentication class on your view(s):

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zgw-auth-backend-1.0.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

zgw_auth_backend-1.0.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file zgw-auth-backend-1.0.0.tar.gz.

File metadata

  • Download URL: zgw-auth-backend-1.0.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for zgw-auth-backend-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b514f95d7a1496505f8542421a4ce6d6eec1861dcba541a6a918d26c143a65f6
MD5 73c3d6f119c9a030ce247833f58fbce3
BLAKE2b-256 0aff99e6cee5ea6d245d964e99a07a55ec0702c04cdc94be19cdee8cd37ad1ad

See more details on using hashes here.

File details

Details for the file zgw_auth_backend-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: zgw_auth_backend-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.8.6

File hashes

Hashes for zgw_auth_backend-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f53d41bdda39bff8bcc1d85aa722617b432a7002b33ca35c9a93c6278a4ac602
MD5 e50cd7b7049f0b75d2c9b9d7c6292bc1
BLAKE2b-256 50c2e024b160d5e436e97a3e44b2b725901eda315ab24cb51ba899bd0a72509a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page