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.4
- Source:
- Keywords:
zgw, vng, apis, drf
- PythonVersion:
3.8
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,)
Add the client credentials in the admin (client ID + secret)
Generate a ZGW auth JWT with the user_id claim, using the credentials from step 1
Make an API call to the endpoint, including the Authorization: Bearer <jwt> header
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
Built Distribution
File details
Details for the file zgw-auth-backend-1.0.4.tar.gz
.
File metadata
- Download URL: zgw-auth-backend-1.0.4.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 241d87c9c05a3a19efe8f486adadc745886164de9f0bfd44b1929854c0baae86 |
|
MD5 | 52332f23dfaea4ba9a00657ce09614a4 |
|
BLAKE2b-256 | 4471efc44c047a21d8b7d7b2e7fa7eb6386189efdd5c910a48340539f8d9d4e3 |
File details
Details for the file zgw_auth_backend-1.0.4-py3-none-any.whl
.
File metadata
- Download URL: zgw_auth_backend-1.0.4-py3-none-any.whl
- Upload date:
- Size: 8.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c22e99fab473b05d87c27d3ed58fd38984d023f42ceb709e8e5475e8c30ae640 |
|
MD5 | 88b22ebd6eae11666531392e80cb853a |
|
BLAKE2b-256 | 4835b1c9079e5dbbefbe9e3f1841aa22b388990cabb8ae5d3d0e0d47a9e5e238 |