Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ whitenoise = "*"
drf-extensions = "*"
django-cors-headers = "*"
django-rest-swagger = "*"
djangorestframework-simplejwt = "*"

[requires]
python_version = "3.7"
27 changes: 22 additions & 5 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions patienttracker/patients/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def setUp(self):
self.my_admin = User.objects.create(username='user')
self.client = APIClient()
user = User.objects.get()
self.client.force_authenticate(user=self.my_admin)

self.valid_payload = {
'first_name' : 'John',
Expand Down
3 changes: 3 additions & 0 deletions patienttracker/patients/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
from .serializers import PatientSerializer, AppointmentSerializer
from .models import Patient, Appointment
from rest_framework_extensions.mixins import NestedViewSetMixin
from rest_framework.permissions import IsAuthenticated

class PatientViewSet(NestedViewSetMixin, ModelViewSet):
serializer_class = PatientSerializer
queryset = Patient.objects.all()
permission_classes = (IsAuthenticated,)

class AppointmentViewSet(NestedViewSetMixin, ModelViewSet):
serializer_class = AppointmentSerializer
queryset = Appointment.objects.all()
permission_classes = (IsAuthenticated,)
40 changes: 40 additions & 0 deletions patienttracker/patienttracker/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import os
import environ
from datetime import timedelta

env = environ.Env(
DEBUG=(bool, False)
Expand Down Expand Up @@ -136,3 +137,42 @@

LOGIN_URL = 'rest_framework:login'
LOGOUT_URL = 'rest_framework:logout'

SWAGGER_SETTINGS = {
'SECURITY_DEFINITIONS': {
'apiKey': {
'type': 'apiKey',
'name': 'Bearer',
'in': 'header'
}
},
}

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_simplejwt.authentication.JWTAuthentication',
'rest_framework.authentication.SessionAuthentication',
],
}

SIMPLE_JWT = {
'ACCESS_TOKEN_LIFETIME': timedelta(minutes=60),
'REFRESH_TOKEN_LIFETIME': timedelta(days=1),
'ROTATE_REFRESH_TOKENS': False,
'BLACKLIST_AFTER_ROTATION': True,

'ALGORITHM': 'HS256',
'SIGNING_KEY': SECRET_KEY,
'VERIFYING_KEY': None,

'AUTH_HEADER_TYPES': ('Bearer',),
'USER_ID_FIELD': 'id',
'USER_ID_CLAIM': 'user_id',

'AUTH_TOKEN_CLASSES': ('rest_framework_simplejwt.tokens.AccessToken',),
'TOKEN_TYPE_CLAIM': 'token_type',

'SLIDING_TOKEN_REFRESH_EXP_CLAIM': 'refresh_exp',
'SLIDING_TOKEN_LIFETIME': timedelta(minutes=5),
'SLIDING_TOKEN_REFRESH_LIFETIME': timedelta(days=1),
}
5 changes: 4 additions & 1 deletion patienttracker/patienttracker/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from django.contrib import admin
from django.urls import path, include
from rest_framework_swagger.views import get_swagger_view
from rest_framework_simplejwt import views as jwt_views

schema_view = get_swagger_view(title='Patient Tracker API')

Expand All @@ -24,5 +25,7 @@
path('', include('patients.urls')),
path('', include('users.urls')),
path('auth/', include('rest_framework.urls')),
path('', schema_view)
path('', schema_view),
path('api/token/', jwt_views.TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('api/token/refresh/', jwt_views.TokenRefreshView.as_view(), name='token_refresh'),
]