This is an JWT authentication plugin for Django REST Framework.
It uses simplejwt to provide the basic url routes. Also it makes use of
custom CustomTokenObtainPairSerializer in order to customize the login response
and CustomTokenObtainPairView to override the default TokenObtainPairView of simplejwt
Available URL routes are:
auth/login- used to obtain the token and refresh token values together with other custom fields. - refer to simplejwt docs for more informationauth/token/refresh- used to refresh to refresh the token. - refer to simplejwt docs for more informationauth/users/register- used to create a new user.
- Clone the project along side your existing apps.
git clone https://github.com/meltiseugen/django-jwt-authentication-plugin.git authplugin
- Install the django-jwt-authentication-plugin requirements.
pip install -r authentication/requirements.txt
-
Add the
authplugin.authenticationapp toINSTALLED_APPSofsettings.py -
Add the new default authentication class to the rest framework.
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_simplejwt.authentication.JWTAuthentication',
)
}
- Add the URL routes to the main url.py of your project.
urlpatterns = [
...
path('api/', include('authplugin.authentication.urls')),
...
]
- Migrate your project in order to create the necessary models in the database.
python manage.py makemigrations && python manage.py migrate
- Remove the .git folder of this repo so that the outer (main) repo will not complain about it and you are free to add more authentication logic to it and commit it to your base repo.