From e648ea1ec460d5f23abfc38712aba041b0699759 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mats=20Paul=20Ton=C4=8Dik?= Date: Sat, 4 Jul 2026 22:37:34 +0200 Subject: [PATCH] feat(backend/auth): added otk response model --- service/src/main/inse/auth/model.py | 7 +++++++ service/src/main/inse/auth/router.py | 3 ++- service/src/main/inse/auth/service.py | 5 +++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/service/src/main/inse/auth/model.py b/service/src/main/inse/auth/model.py index a79aa113..21d7d706 100644 --- a/service/src/main/inse/auth/model.py +++ b/service/src/main/inse/auth/model.py @@ -210,3 +210,10 @@ class AccessResponse(BaseModel): refresh_token: RefreshToken = Field( description="The refresh token issued alongside the access token for obtaining new access tokens." ) + + +class OtkResponse(BaseModel): + status: str = Field(description="The status of the one-time code (OTC) request.") + account_id: uuid.UUID = Field( + description="The unique identifier of the account for which the OTC was requested." + ) diff --git a/service/src/main/inse/auth/router.py b/service/src/main/inse/auth/router.py index 2ce4f52a..e80612bb 100644 --- a/service/src/main/inse/auth/router.py +++ b/service/src/main/inse/auth/router.py @@ -14,6 +14,7 @@ from inse.auth.model import ( AccessToken, IdToken, LoginResponse, + OtkResponse, RefreshToken, ) @@ -40,7 +41,7 @@ async def request_otk( session: SessionDep, email: Annotated[str, Body(description="User's email address")], password: Annotated[str, Body(description="User's password")], -): +) -> OtkResponse: return auth_service.request_otk(session=session, email=email, password=password) diff --git a/service/src/main/inse/auth/service.py b/service/src/main/inse/auth/service.py index 0af15a4b..dfaa1bf3 100644 --- a/service/src/main/inse/auth/service.py +++ b/service/src/main/inse/auth/service.py @@ -18,6 +18,7 @@ from inse.auth.model import ( IdToken, LoginResponse, Organization, + OtkResponse, RefreshToken, Secret, TokenType, @@ -155,7 +156,7 @@ def _verify_password(password: str, password_hash: str) -> bool: return False -def request_otk(session: Session, email: str, password: str): +def request_otk(session: Session, email: str, password: str) -> OtkResponse: """Requests a one-time key (OTK) for authentication using email and password. Validates the provided credentials and generates a one-time key if valid. Args: @@ -236,7 +237,7 @@ def request_otk(session: Session, email: str, password: str): else: logger.info("OTK generated for account %s", account.id) - return {"status": "ok", "account_id": str(account.id)} + return OtkResponse(status="success", account_id=account.id) def login(