diff --git a/requirements.txt b/requirements.txt index c771340..7a32b75 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,9 +2,11 @@ astroid==2.3.3 Django==2.2.7 django-cors-headers==3.2.0 djangorestframework==3.10.3 +djangorestframework-simplejwt==4.3.0 isort==4.3.21 lazy-object-proxy==1.4.3 mccabe==0.6.1 +PyJWT==1.7.1 pylint==2.4.4 pytz==2019.3 six==1.13.0 diff --git a/segnalibre/settings.py b/segnalibre/settings.py index b1bfa78..83ba89d 100644 --- a/segnalibre/settings.py +++ b/segnalibre/settings.py @@ -128,6 +128,12 @@ CORS_ORIGIN_WHITELIST = [ ] REST_FRAMEWORK = { + 'DEFAULT_AUTHENTICATION_CLASSES': [ + 'rest_framework_simplejwt.authentication.JWTAuthentication' + ], + 'DEFAULT_PERMISSION_CLASSES': ( + 'rest_framework.permissions.IsAuthenticated' + ), 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination', 'PAGE_SIZE': 10 } \ No newline at end of file diff --git a/segnalibre_app/urls.py b/segnalibre_app/urls.py index 91e5d2e..4114778 100644 --- a/segnalibre_app/urls.py +++ b/segnalibre_app/urls.py @@ -1,5 +1,9 @@ from django.urls import path, include from . import views +from rest_framework_simplejwt.views import ( + TokenObtainPairView, + TokenRefreshView, + TokenVerifyView) prefix = 'v1/' @@ -7,5 +11,8 @@ urlpatterns = [ path(prefix + 'users/', views.UserList.as_view()), path(prefix + 'books/', views.BookList.as_view()), path(prefix +'books//', views.BookDetail.as_view()), - path('api-auth/', include('rest_framework.urls')) + path('api-auth/', include('rest_framework.urls')), + path(prefix + 'auth/token', TokenObtainPairView.as_view(), name='token_obtain_pair'), + path(prefix + 'auth/refresh', TokenRefreshView.as_view(), name='token_refresh'), + path(prefix + 'auth/verify', TokenVerifyView.as_view(), name='token_verify') ] \ No newline at end of file