diff --git a/app/routers/auth.py b/app/routers/auth.py index e85d4cb..11218a4 100644 --- a/app/routers/auth.py +++ b/app/routers/auth.py @@ -7,6 +7,7 @@ from fastapi.responses import StreamingResponse from app.models import User +from app.types.frontend import LoginFormWith2FA from app.types.pydantic_models import Token, Enable2FA from app.utils import authenticate_user, generate_user_token from app.security import TwoFactorAuth @@ -46,7 +47,7 @@ async def login_without_2fa( @router.post("/2fa/is-2fa-active/") async def is_2fa_active( - form_data: Annotated[OAuth2PasswordRequestForm, Depends()], + form_data: Annotated[LoginFormWith2FA, Depends()], ) -> bool: user = await authenticate_user(form_data.username, form_data.password) if not user: @@ -61,8 +62,7 @@ async def is_2fa_active( @router.post("/2fa/login/") async def login_with_2fa( - form_data: Annotated[OAuth2PasswordRequestForm, Depends()], - totp_code: str, + form_data: Annotated[LoginFormWith2FA, Depends()], ) -> Token: user = await authenticate_user(form_data.username, form_data.password) @@ -76,7 +76,7 @@ async def login_with_2fa( secret_key = await TwoFactorAuth.get_or_create_secret_key(user.id) two_factor_auth = TwoFactorAuth(user.id, secret_key) - is_valid = two_factor_auth.verify_totp_code(totp_code) + is_valid = two_factor_auth.verify_totp_code(form_data.totp_code) if not is_valid: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, @@ -107,7 +107,7 @@ async def enable_2fa( @router.post("/2fa/generate-qrcode/") async def generate_qrcode( - form_data: Annotated[OAuth2PasswordRequestForm, Depends()], + form_data: Annotated[LoginFormWith2FA, Depends()], ) -> bytes: current_user = await authenticate_user(form_data.username, form_data.password) if not current_user: