mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-29 01:20:02 +03:00
Refa(authentication): improve code quality
This commit is contained in:
parent
580bf45ccf
commit
d83a794216
|
@ -65,13 +65,10 @@ class BasicAuthentication(BaseAuthentication):
|
||||||
|
|
||||||
if not auth or auth[0].lower() != b'basic':
|
if not auth or auth[0].lower() != b'basic':
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if len(auth) == 1:
|
if len(auth) != 2:
|
||||||
msg = _('Invalid basic header. No credentials provided.')
|
msg = _('Invalid basic header. No credentials provided.')
|
||||||
raise exceptions.AuthenticationFailed(msg)
|
raise exceptions.AuthenticationFailed(msg)
|
||||||
elif len(auth) > 2:
|
|
||||||
msg = _('Invalid basic header. Credentials string should not contain spaces.')
|
|
||||||
raise exceptions.AuthenticationFailed(msg)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
|
@ -180,12 +177,9 @@ class TokenAuthentication(BaseAuthentication):
|
||||||
if not auth or auth[0].lower() != self.keyword.lower().encode():
|
if not auth or auth[0].lower() != self.keyword.lower().encode():
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if len(auth) == 1:
|
if len(auth) != 2:
|
||||||
msg = _('Invalid token header. No credentials provided.')
|
msg = _('Invalid token header. No credentials provided.')
|
||||||
raise exceptions.AuthenticationFailed(msg)
|
raise exceptions.AuthenticationFailed(msg)
|
||||||
elif len(auth) > 2:
|
|
||||||
msg = _('Invalid token header. Token string should not contain spaces.')
|
|
||||||
raise exceptions.AuthenticationFailed(msg)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
token = auth[1].decode()
|
token = auth[1].decode()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user