replace partition with split in BasicAuthentication

This commit is contained in:
Liljack118 2022-12-03 15:38:14 +01:00
parent cc3c89a11c
commit 05eded4e28

View File

@ -78,12 +78,12 @@ class BasicAuthentication(BaseAuthentication):
auth_decoded = base64.b64decode(auth[1]).decode('utf-8') auth_decoded = base64.b64decode(auth[1]).decode('utf-8')
except UnicodeDecodeError: except UnicodeDecodeError:
auth_decoded = base64.b64decode(auth[1]).decode('latin-1') auth_decoded = base64.b64decode(auth[1]).decode('latin-1')
auth_parts = auth_decoded.partition(':')
except (TypeError, UnicodeDecodeError, binascii.Error): userid, password = auth_decoded.split(':', 1)
except (TypeError, ValueError, UnicodeDecodeError, binascii.Error):
msg = _('Invalid basic header. Credentials not correctly base64 encoded.') msg = _('Invalid basic header. Credentials not correctly base64 encoded.')
raise exceptions.AuthenticationFailed(msg) raise exceptions.AuthenticationFailed(msg)
userid, password = auth_parts[0], auth_parts[2]
return self.authenticate_credentials(userid, password, request) return self.authenticate_credentials(userid, password, request)
def authenticate_credentials(self, userid, password, request=None): def authenticate_credentials(self, userid, password, request=None):