diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py index 382abf158..4a4d0f8aa 100644 --- a/rest_framework/authentication.py +++ b/rest_framework/authentication.py @@ -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()