From ced8c9f75cc1ed9622c87db9d69718de7c2dc0c8 Mon Sep 17 00:00:00 2001 From: Untone Date: Mon, 26 Feb 2024 12:52:22 +0300 Subject: [PATCH] error-handle-create-shout-2 --- services/auth.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/services/auth.py b/services/auth.py index 6142ea30..e1fae850 100644 --- a/services/auth.py +++ b/services/auth.py @@ -1,6 +1,6 @@ from functools import wraps import httpx - +from starlette.exceptions import HTTPException from settings import ADMIN_SECRET, AUTH_URL from services.logger import root_logger as logger @@ -45,6 +45,7 @@ async def check_auth(req): } data = await request_data(gql) if data: + logger.debug(data) user_data = data.get('data', {}).get(query_name, {}).get('claims', {}) user_id = user_data.get('sub') user_roles = user_data.get('allowed_roles') @@ -82,7 +83,9 @@ def login_required(f): logger.info(f' got {user_id} roles: {user_roles}') context['user_id'] = user_id.strip() context['roles'] = user_roles - return await f(*args, **kwargs) + return await f(*args, **kwargs) + else: + raise HTTPException(status_code=401, detail='Unauthorized') return decorated_function @@ -95,6 +98,8 @@ def auth_request(f): if user_id: req['user_id'] = user_id.strip() req['roles'] = user_roles - return await f(*args, **kwargs) + return await f(*args, **kwargs) + else: + raise HTTPException(status_code=401, detail='Unauthorized') return decorated_function