Skip to content

Commit

Permalink
New LoginForm for 2FA use
Browse files Browse the repository at this point in the history
  • Loading branch information
TanookiVerde committed Sep 2, 2024
1 parent 2ca1daa commit e301a35
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/routers/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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,
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit e301a35

Please sign in to comment.