Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions knox/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down