mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 11:30:12 +03:00
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.
This commit is contained in:
parent
9d001cd84c
commit
d824ab677b
|
@ -189,9 +189,9 @@ class TokenAuthentication(BaseAuthentication):
|
||||||
msg = _('Invalid token header. Token string should not contain invalid characters.')
|
msg = _('Invalid token header. Token string should not contain invalid characters.')
|
||||||
raise exceptions.AuthenticationFailed(msg)
|
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()
|
model = self.get_model()
|
||||||
try:
|
try:
|
||||||
token = model.objects.select_related('user').get(key=key)
|
token = model.objects.select_related('user').get(key=key)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user