diff --git a/litestar/security/jwt/middleware.py b/litestar/security/jwt/middleware.py index 305f4011a3..cad5925371 100644 --- a/litestar/security/jwt/middleware.py +++ b/litestar/security/jwt/middleware.py @@ -251,5 +251,6 @@ async def authenticate_request(self, connection: ASGIConnection[Any, Any, Any, A auth_header = connection.headers.get(self.auth_header) or connection.cookies.get(self.auth_cookie_key) if not auth_header: raise NotAuthorizedException("No JWT token found in request header or cookies") - encoded_token = auth_header.partition(" ")[-1] + parts = auth_header.strip().split(maxsplit=1) + encoded_token = parts[-1] if parts else "" return await self.authenticate_token(encoded_token=encoded_token, connection=connection)