From d824ab677bb4b0dd5be1c6f90d08bf7b18da3ded Mon Sep 17 00:00:00 2001 From: Konstantin Alekseev Date: Sat, 27 Oct 2018 20:17:54 +0300 Subject: [PATCH] Pass request to authenticate_credentials in TokenAuthentication It may help if you need to filter tokens based on information from request. E.g. in multi-tenant application request may contain current tenant object. --- rest_framework/authentication.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py index 25150d525..e992e4dfb 100644 --- a/rest_framework/authentication.py +++ b/rest_framework/authentication.py @@ -189,9 +189,9 @@ class TokenAuthentication(BaseAuthentication): msg = _('Invalid token header. Token string should not contain invalid characters.') raise exceptions.AuthenticationFailed(msg) - return self.authenticate_credentials(token) + return self.authenticate_credentials(token, request) - def authenticate_credentials(self, key): + def authenticate_credentials(self, key, request=None): model = self.get_model() try: token = model.objects.select_related('user').get(key=key)