Refa(authentication): improve code quality

This commit is contained in:
Farid Darabi 2021-11-24 14:15:01 +03:30 committed by GitHub
parent 580bf45ccf
commit d83a794216
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -65,13 +65,10 @@ class BasicAuthentication(BaseAuthentication):
if not auth or auth[0].lower() != b'basic':
return None
if len(auth) == 1:
if len(auth) != 2:
msg = _('Invalid basic header. No credentials provided.')
raise exceptions.AuthenticationFailed(msg)
elif len(auth) > 2:
msg = _('Invalid basic header. Credentials string should not contain spaces.')
raise exceptions.AuthenticationFailed(msg)
try:
try:
@ -180,12 +177,9 @@ class TokenAuthentication(BaseAuthentication):
if not auth or auth[0].lower() != self.keyword.lower().encode():
return None
if len(auth) == 1:
if len(auth) != 2:
msg = _('Invalid token header. No credentials provided.')
raise exceptions.AuthenticationFailed(msg)
elif len(auth) > 2:
msg = _('Invalid token header. Token string should not contain spaces.')
raise exceptions.AuthenticationFailed(msg)
try:
token = auth[1].decode()