More logging

This commit is contained in:
PCoder 2019-02-11 01:06:21 +01:00
parent 1b4107306b
commit d38b5378b0
2 changed files with 10 additions and 2 deletions

View file

@ -47,13 +47,16 @@ class TokenSerializer(serializers.Serializer):
# 1. Verify that the connection might authenticate # 1. Verify that the connection might authenticate
try: try:
logger.debug("Checking in db for name:{} & realm:{}".format(
auth_name, auth_realm
))
db_instance = otpauth.models.OTPSeed.objects.get(name=auth_name, realm=auth_realm) db_instance = otpauth.models.OTPSeed.objects.get(name=auth_name, realm=auth_realm)
except (OTPSeed.MultipleObjectsReturned, OTPSeed.DoesNotExist): except (OTPSeed.MultipleObjectsReturned, OTPSeed.DoesNotExist):
logger.error("OTPSeed name: {}, realm: {} does not exist".format( logger.error("OTPSeed name: {}, realm: {} does not exist".format(
auth_name, auth_realm auth_name, auth_realm
)) ))
raise exceptions.AuthenticationFailed() raise exceptions.AuthenticationFailed()
logger.debug("Found seed: {}".format(db_instance.seed))
totp = pyotp.TOTP(db_instance.seed) totp = pyotp.TOTP(db_instance.seed)
logger.debug("calculated token = {}".format(totp.now())) logger.debug("calculated token = {}".format(totp.now()))

View file

@ -7,6 +7,11 @@ from rest_framework.response import Response
from django.http import JsonResponse from django.http import JsonResponse
from otpauth.serializer import VerifySerializer, OTPSerializer, TokenSerializer from otpauth.serializer import VerifySerializer, OTPSerializer, TokenSerializer
from otpauth.models import OTPSeed from otpauth.models import OTPSeed
import json
import logging
logger = logging.getLogger(__name__)
class OTPVerifyViewSet(viewsets.ModelViewSet): class OTPVerifyViewSet(viewsets.ModelViewSet):
serializer_class = OTPSerializer serializer_class = OTPSerializer
@ -20,7 +25,7 @@ class OTPVerifyViewSet(viewsets.ModelViewSet):
Now we inspect the payload and return ok, Now we inspect the payload and return ok,
if they also verify if they also verify
""" """
logger.debug("in verify {}".format(json.dumps(request.data)))
serializer = VerifySerializer(data=request.data) serializer = VerifySerializer(data=request.data)
if serializer.is_valid(): if serializer.is_valid():
serializer.save() serializer.save()