Add logging
This commit is contained in:
parent
d598b9584e
commit
1b4107306b
1 changed files with 8 additions and 1 deletions
|
@ -2,6 +2,10 @@ from django.db import models
|
||||||
from django.contrib.auth.models import AbstractUser
|
from django.contrib.auth.models import AbstractUser
|
||||||
from rest_framework import exceptions
|
from rest_framework import exceptions
|
||||||
from rest_framework import authentication
|
from rest_framework import authentication
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class OTPSeed(AbstractUser):
|
class OTPSeed(AbstractUser):
|
||||||
|
@ -27,17 +31,20 @@ from otpauth.serializer import TokenSerializer
|
||||||
|
|
||||||
class OTPAuthentication(authentication.BaseAuthentication):
|
class OTPAuthentication(authentication.BaseAuthentication):
|
||||||
def authenticate(self, request):
|
def authenticate(self, request):
|
||||||
|
logger.debug("in authenticate {}".format(json.dumps(request.data)))
|
||||||
serializer = TokenSerializer(data=request.data)
|
serializer = TokenSerializer(data=request.data)
|
||||||
|
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
instance, token = serializer.save()
|
instance, token = serializer.save()
|
||||||
else:
|
else:
|
||||||
|
logger.error("serializer is invalid")
|
||||||
raise exceptions.AuthenticationFailed()
|
raise exceptions.AuthenticationFailed()
|
||||||
|
|
||||||
# not dealing with admin realm -> can only be auth [see serializer]
|
# not dealing with admin realm -> can only be auth [see serializer]
|
||||||
if not instance.realm == "ungleich-admin":
|
if not instance.realm == "ungleich-admin":
|
||||||
if not request.path == "/ungleichotp/verify/":
|
if not request.path == "/ungleichotp/verify/":
|
||||||
|
logger.debug("request.path is not /ungleichotp/verify/")
|
||||||
raise exceptions.AuthenticationFailed()
|
raise exceptions.AuthenticationFailed()
|
||||||
|
|
||||||
# print("AUTH DONE: {} - {}".format(request.path, instance))
|
logger.debug("AUTH DONE: {} - {}".format(request.path, instance))
|
||||||
return (instance, token)
|
return (instance, token)
|
||||||
|
|
Loading…
Reference in a new issue