Goal of this simple package is to create a simple JWT authentication for Django apps. This should be easy to configue and easy to adapt to your needs and preferences. Package is based on PyJWT
-
Install package
pip install django-drf-mjwt
-
Add django_drf_jwt to your INSTALLED_APPS:
INSTALLED_APPS = [ # ... "django_drf_jwt", # ... ]
-
Update REST_FRAMEWORK settings:
REST_FRAMEWORK = { # ... "DEFAULT_AUTHENTICATION_CLASSES": ( "django_drf_jwt.authentication.JWTAuthentication", ) # ... }
-
Add new field in your User model and add this to your settings file
JWT_DRF = { # JWT_USER_SECRET_FIELD - MUST BE DEFINED - This must be filed in User object "JWT_USER_SECRET_FIELD": "secret", }
Available settings:
# These are default settings JWT_DRF = { "JWT_SECRET": settings.SECRET_KEY, "JWT_USER_ID_FIELD": "pk", "JWT_USER_SECRET_FIELD": None, # MUST BE DEFINED - This must be a "JWT_PAYLOAD_HANDLER": "django_drf_jwt.handlers.payload_handler", "JWT_AUTH_HEADER_PREFIX": "JWT", }
To setup environment for local developing install requirements from requirements.txt file.
Make sure that you write tests for your implementation.
If you have any suggestions or you see some issues and bugs be free to contact me!