From 9dc6e020290e45ef6830d6c26b9d31e60623c609 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sun, 18 Nov 2018 13:05:21 +0100 Subject: [PATCH] Auth: set token as request.auth --- ungleichotp/otpauth/models.py | 4 ++-- ungleichotp/otpauth/serializer.py | 2 +- ungleichotp/ungleichotp/settings.py | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ungleichotp/otpauth/models.py b/ungleichotp/otpauth/models.py index 78e7e57..b815593 100644 --- a/ungleichotp/otpauth/models.py +++ b/ungleichotp/otpauth/models.py @@ -39,8 +39,8 @@ class OTPAuthentication(authentication.BaseAuthentication): if serializer.is_valid(): print("trying to save... {}".format(serializer)) - user = serializer.save() + user, token = serializer.save() else: raise exceptions.AuthenticationFailed() - return (user, None) + return (user, token) diff --git a/ungleichotp/otpauth/serializer.py b/ungleichotp/otpauth/serializer.py index 2986157..b592da9 100644 --- a/ungleichotp/otpauth/serializer.py +++ b/ungleichotp/otpauth/serializer.py @@ -78,4 +78,4 @@ class TokenSerializer(serializers.Serializer): if not totp.verify(token_in, valid_window=3): raise exceptions.AuthenticationFailed() - return db_instance + return (db_instance, token_in) diff --git a/ungleichotp/ungleichotp/settings.py b/ungleichotp/ungleichotp/settings.py index af24e79..21646ab 100644 --- a/ungleichotp/ungleichotp/settings.py +++ b/ungleichotp/ungleichotp/settings.py @@ -104,6 +104,7 @@ AUTH_PASSWORD_VALIDATORS = [ REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( + 'rest_framework.authentication.SessionAuthentication', 'otpauth.models.OTPAuthentication' ) }