From d1ded0730b82b7c2df60407cc54251dee8d4b986 Mon Sep 17 00:00:00 2001 From: Cizz22 Date: Tue, 14 Oct 2025 04:39:01 +0700 Subject: [PATCH] fix token --- src/auth/service.py | 25 +++++++++++++++++++++++ src/calculation_time_constrains/router.py | 4 ++-- src/config.py | 2 +- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/auth/service.py b/src/auth/service.py index 542dc1d..88ec27d 100644 --- a/src/auth/service.py +++ b/src/auth/service.py @@ -80,5 +80,30 @@ async def get_token(request: Request): return "" +async def internal_key(request: Request): + api_key = request.headers.get("X-Internal-Key") + + if api_key != config.API_KEY: + raise HTTPException( + status_code=403, detail="Invalid Key." + ) + + response = requests.post( + f"{config.AUTH_SERVICE_API}/sign-in", + data={ + "username": "user10", + "password": "123456" + } + ) + + if not response.ok: + return False, response.json() + + user_data = response.json() + return user_data['data']['access_token'] + + + CurrentUser = Annotated[UserBase, Depends(get_current_user)] Token = Annotated[str, Depends(get_token)] +InternalKey = Annotated[str, Depends(internal_key)] \ No newline at end of file diff --git a/src/calculation_time_constrains/router.py b/src/calculation_time_constrains/router.py index e2af527..4a985cd 100644 --- a/src/calculation_time_constrains/router.py +++ b/src/calculation_time_constrains/router.py @@ -3,7 +3,7 @@ from typing import List, Optional, Union from fastapi import APIRouter from fastapi.params import Query -from src.auth.service import CurrentUser, Token +from src.auth.service import CurrentUser, InternalKey, Token from src.config import DEFAULT_TC_ID from src.database.core import DbSession from src.models import StandardResponse @@ -85,7 +85,7 @@ async def get_calculation_parameters( @router.get( "/{calculation_id}", response_model=StandardResponse[CalculationTimeConstrainsRead] ) -async def get_calculation_results(db_session: DbSession, calculation_id, token:Token): +async def get_calculation_results(db_session: DbSession, calculation_id, token:InternalKey): if calculation_id == 'default': calculation_id = DEFAULT_TC_ID diff --git a/src/config.py b/src/config.py index 005abde..d7c92b7 100644 --- a/src/config.py +++ b/src/config.py @@ -87,7 +87,7 @@ RBD_SERVICE_API = config("RBD_SERVICE_API", default="http://192.168.1.82:8000/rb TEMPORAL_URL = config("TEMPORAL_URL", default="http://192.168.1.86:7233") - +API_KEY = config("API_KEY", default="0KFvcB7zWENyKVjoma9FKZNofVSViEshYr59zEQNGaYjyUP34gCJKDuqHuk9VfvE") TR_RBD_ID = config("TR_RBD_ID", default="f04f365e-25d8-4036-87c2-ba1bfe1f9229") TC_RBD_ID = config("TC_RBD_ID", default="f8523cb0-dc3c-4edb-bcf1-eea7b62582f1")