From 05d85eaf874eeef59d10ac4cffabd3730e9ebe4b Mon Sep 17 00:00:00 2001 From: Evgeny Bushkov Date: Fri, 6 Nov 2026 14:11:13 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=D0=BF=D1=80=D0=B8=D0=BD=D0=B8=D0=BC?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D1=82=D0=BE=D0=BA=D0=B5=D0=BD=20=D0=B1?= =?UTF-8?q?=D0=B5=D0=B7=20=D0=BF=D1=80=D0=B5=D1=84=D0=B8=D0=BA=D1=81=D0=B0?= =?UTF-8?q?=20Bearer=20=D0=B2=20current=5Fuser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: aider (deepseek/deepseek-chat) --- app/deps.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/deps.py b/app/deps.py index 2c590734..dba04b29 100644 --- a/app/deps.py +++ b/app/deps.py @@ -20,10 +20,15 @@ def get_db(): def current_user(request: Request, db: Session = Depends(get_db)) -> User: - auth = request.headers.get("authorization", "") - if not auth.lower().startswith("bearer "): + auth = request.headers.get("authorization", "").strip() + if not auth: raise ApiError(401, "unauthorized", "Требуется Bearer-токен") - token = auth[7:].strip() + # Swagger UI для bearerAuth подставляет токен без префикса "Bearer ". + # Принимаем оба варианта: "Bearer " и "". + if auth.lower().startswith("bearer "): + token = auth[7:].strip() + else: + token = auth if not token: raise ApiError(401, "unauthorized", "Пустой токен") row = db.get(SessionRow, token_hash(token))