django-auth-jwks
django-auth-jwks is a reusable Django app for verifying JWT tokens via JSON Web Key Sets (JWKS) with caching support. It is designed to work seamlessly with Django REST Framework (DRF) and supports both database-backed and stateless authentication scenarios.
Note: This package is currently in beta. Features and APIs may change in future releases.
Features
- JWT Verification: Validate JWT tokens using JWKS.
- Stateless Authentication: Supports servers without a database or user model.
- Database Integration: Maps JWT claims to Django user models when available.
- Caching: Efficiently caches JWKS for improved performance.
- DRF Integration: Works with Django REST Framework for API authentication.
Installation
Install the package using pip:
pip install django-auth-jwks
Alternatively, for development purposes, you can install it in editable mode:
pip install -e .
To uninstall the package:
pip uninstall django-auth-jwks
Quickstart
-
Add
django_auth_jwksto yourINSTALLED_APPSinsettings.py:INSTALLED_APPS = [ ..., "django_auth_jwks", ]
-
Configure the
AUTH_JWKSsetting in your Django project to point to your JWKS URL:AUTH_JWKS = { "ISSUER": "https://example.com", "JWKS_ENDPOINT": "/o/.well-known/jwks.json", "AUDIENCE": "example-service", "CACHE_TTL": 300, }
-
Use the
JWTAuthenticationclass in your DRF settings:REST_FRAMEWORK = { "DEFAULT_AUTHENTICATION_CLASSES": [ "django_auth_jwks.authentication.JWTAuthentication", ], }
-
Optionally, use the
@require_authdecorator or middleware for securing views. -
Run your Django server:
python manage.py runserver
Usage
Securing Views with the @require_auth Decorator
You can secure individual views by applying the @require_auth decorator:
from django_auth_jwks.decorators import require_auth
@require_auth
def my_view(request):
return JsonResponse({"message": "Authenticated!"})
Using Middleware for Global Authentication
To apply authentication globally, add the middleware to your MIDDLEWARE setting:
MIDDLEWARE = [
...,
"django_auth_jwks.middleware.JWTAuthenticationMiddleware",
]
Development
To contribute to this project:
-
Clone the repository.
-
Install dependencies:
pip install -r requirements.txt
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
Disclaimer
This package is in beta. Use it in production environments with caution, and report any issues you encounter.
Metadata
Release files for django-auth-jwks 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_auth_jwks-1.0.1.tar.gz | 5.2 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_auth_jwks-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 12.2 kB
Release files / django_auth_jwks-1.0.1.tar.gz
| Download URL | django_auth_jwks-1.0.1.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
157dfe9d527cc62d7a17817037c110af9d2214d881b561f95018f9c8e8167ca4
|
|
BLAKE2b-256 checksum How to use checksums |
e4ffc2626f76676d5222d4261c644c9341df18ace04fd6c11ac47b302dbd316f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2025.
Transparency logRelease files / django_auth_jwks-1.0.1-py3-none-any.whl
| Download URL | django_auth_jwks-1.0.1-py3-none-any.whl |
|---|---|
| Size | 6.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
548d37088cfb7e566fb4b85e2eccab188baa0d68e9e7410941a5065e2813f111
|
|
BLAKE2b-256 checksum How to use checksums |
8e7426d318ddaf0d989b3750b32db9e6490f162ede4e54c1b7f79dff450f77cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2025.
Transparency logSecurity for django-auth-jwks 1.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for django_auth_jwks-1.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.