Skip to content

Commit

Permalink
Remove filter loop as digest is a primary key
Browse files Browse the repository at this point in the history
  • Loading branch information
jmsmkn committed Aug 3, 2024
1 parent c2b7f46 commit 7034480
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions knox/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,18 @@ def authenticate_credentials(self, token):
except (TypeError, binascii.Error):
raise exceptions.AuthenticationFailed(msg)

for auth_token in get_token_model().objects.filter(
digest=digest,
):
if self._cleanup_token(auth_token):
continue

if knox_settings.AUTO_REFRESH and auth_token.expiry:
self.renew_token(auth_token)
return self.validate_user(auth_token)
raise exceptions.AuthenticationFailed(msg)
try:
auth_token = get_token_model().objects.get(digest=digest)
except get_token_model().DoesNotExist:
raise exceptions.AuthenticationFailed(msg)

if self._cleanup_token(auth_token):
raise exceptions.AuthenticationFailed(msg)

if knox_settings.AUTO_REFRESH and auth_token.expiry:
self.renew_token(auth_token)

return self.validate_user(auth_token)

def renew_token(self, auth_token) -> None:
current_expiry = auth_token.expiry
Expand Down

0 comments on commit 7034480

Please sign in to comment.