diff --git a/knox/auth.py b/knox/auth.py index c013c4dd..8f9d3bc6 100644 --- a/knox/auth.py +++ b/knox/auth.py @@ -14,7 +14,6 @@ def compare_digest(a, b): ) from knox.crypto import hash_token -from knox.models import AuthToken from knox.settings import CONSTANTS, knox_settings from knox.signals import token_expired @@ -31,7 +30,13 @@ class TokenAuthentication(BaseAuthentication): - `request.user` will be a django `User` instance - `request.auth` will be an `AuthToken` instance ''' - model = AuthToken + model = None + + def get_model(self): + if self.model is not None: + return self.model + from knox.models import AuthToken + return AuthToken def authenticate(self, request): auth = get_authorization_header(request).split() @@ -62,7 +67,7 @@ def authenticate_credentials(self, token): ''' msg = _('Invalid token.') token = token.decode("utf-8") - for auth_token in AuthToken.objects.filter( + for auth_token in self.get_model().objects.filter( token_key=token[:CONSTANTS.TOKEN_KEY_LENGTH]): if self._cleanup_token(auth_token): continue