From 5a7e51ae940bb25912b4acc39c816e0511e1621c Mon Sep 17 00:00:00 2001 From: Maxime Alves LIRMM Date: Fri, 3 Feb 2023 14:20:01 +0100 Subject: [PATCH] =?UTF-8?q?[jwtMiddleware]=C2=A0clean=20"is=5Ffake=5Fuser?= =?UTF-8?q?=5Fid"=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- halfapi/lib/jwt_middleware.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/halfapi/lib/jwt_middleware.py b/halfapi/lib/jwt_middleware.py index 5faa48b..d9578fd 100644 --- a/halfapi/lib/jwt_middleware.py +++ b/halfapi/lib/jwt_middleware.py @@ -70,14 +70,14 @@ class JWTAuthenticationBackend(AuthenticationBackend): token = cookies_from_scope(conn.scope).get('Authorization') is_check_call = 'check' in conn.query_params - is_fake_user_id = is_check_call and 'user_id' in conn.query_params + PRODUCTION = conn.scope['app'].debug == False if not token and not is_check_call: return AuthCredentials(), Nobody() try: - if token and not is_fake_user_id: + if token: payload = jwt.decode(token, key=self.secret_key, algorithms=[self.algorithm], @@ -86,14 +86,6 @@ class JWTAuthenticationBackend(AuthenticationBackend): }) if is_check_call: - if is_fake_user_id: - try: - fake_user_id = UUID(conn.query_params['user_id']) - - return AuthCredentials(), CheckUser(fake_user_id) - except ValueError as exc: - raise HTTPException(400, 'user_id parameter not an uuid') - if token: return AuthCredentials(), CheckUser(payload['user_id'])