add fingerprint httpbearer schema

This commit is contained in:
IluaAir
2025-09-21 21:35:46 +03:00
parent 408e32d05f
commit 3dc36a2f25
4 changed files with 31 additions and 18 deletions

View File

@@ -1,6 +1,6 @@
from typing import Annotated
from fastapi import APIRouter, Cookie, Depends, HTTPException, Response
from fastapi import APIRouter, Body, Cookie, Depends, Form, HTTPException, Response
from fastapi.security import OAuth2PasswordRequestForm
from src.api.dependacies.db_dep import sessionDep
@@ -27,15 +27,16 @@ async def login(
session: sessionDep,
credential: Annotated[OAuth2PasswordRequestForm, Depends()],
response: Response,
fingerprint: str = Form(),
):
result = await AuthService(session).login(credential.username, credential.password)
result = await AuthService(session).login(credential.username, credential.password, fingerprint=fingerprint)
response.set_cookie(
key="refresh_token",
value=result["refresh_token"],
httponly=True,
samesite="lax",
path=settings.api.v1.auth,
max_age=60 * 60 * 24 * 7,
max_age=60 * 60 * 24 * settings.refresh_token.expire_days,
)
return result
@@ -43,20 +44,21 @@ async def login(
@router.post(path="/refresh", response_model=Token)
async def refresh(
session: sessionDep,
response: Response,
current_user: RefreshUser,
response: Response,
fingerprint: str = Body(),
refresh_token: Annotated[str | None, Cookie(name="refresh_token")] = None,
):
if refresh_token is None:
raise HTTPException(status_code=401, detail="No refresh token")
result = await AuthService(session).refresh_tokens(refresh_token, current_user)
result = await AuthService(session).refresh_tokens(refresh_token, current_user, fingerprint)
response.set_cookie(
key="refresh_token",
value=result["refresh_token"],
httponly=True,
samesite="lax",
path=settings.api.v1.auth,
max_age=60 * 60 * 24 * 7,
max_age=60 * 60 * 24 * settings.refresh_token.expire_days,
)
return result