GITHUB Repo: https://github.com/ShouravAhmed/django-react-practice-code/tree/main/Django/djtodo
I have implemented a simple To-do app for testing JWT authentication in Django.
Here I have used simple-jwt: https://django-rest-framework-simplejwt.readthedocs.io/
And for OTP-based authentication, I have created a custom user model and also overridden the TokenObtainPairSerializer
from simple-jwt.
Token routes are working fine but the issue i am facing is
// -------------------------------------------------------------
// views.py
// @ removed
// -------------------------------------------------------------
authentication_classes([TokenAuthentication])
permission_classes([IsAuthenticated])
api_view(['GET'])
def get_todos(request):
resp = {'status': 200, 'message': 'success'}
try:
todos = Todo.objects.all()
serializer = TodoSerializer(todos, many=True)
resp['count'] = len(serializer.data)
resp['data'] = serializer.data
except Exception as e:
resp['status'] = 400
resp['message'] = 'Exception Occered'
resp['exception'] = str(e)
return Response(resp)
// -------------------------------------------------------------
// -------------------------------------------------------------
// urls.py
// -------------------------------------------------------------
path('get-todos/', get_todos, name='get_todos'),
// -------------------------------------------------------------
This route is being accessed without providing an authentication token.