refresh tokens 0.1.3

This commit is contained in:
2026-07-23 21:44:35 +03:00
parent eab78b6679
commit be8eb0c485
7 changed files with 78 additions and 28 deletions
+14 -3
View File
@@ -1,4 +1,3 @@
from datetime import timedelta
from fastapi import APIRouter, Depends, Request, Response, Cookie
from fastapi.security import OAuth2PasswordRequestForm, OAuth2PasswordBearer
from src.models.configs_read.env import env_settings
@@ -26,8 +25,20 @@ async def get_access_token(request: Request,response:Response, form_data:OAuth2P
@router.post("/refresh")
async def get_refresh_token(request:Request, refresh_token: str = Cookie())->dict:
return {"access_token":auth.refresh_token(refresh_token=refresh_token,request=request, expires_delta=timedelta(minutes=env_settings.ACCESS_TOKEN_EXPIRE_MINUTES)), "token_type": "bearer"}
async def get_refresh_token(request:Request,response:Response, refresh_token: str = Cookie())->dict:
access_token, refresh_token= auth.refresh_token(refresh_token=refresh_token,request=request)
response.set_cookie(
key="refresh_token",
value=refresh_token,
httponly=True,
secure=True,
samesite="strict",
max_age=env_settings.REFRESH_TOKEN_EXPIRE_DAYS * 24 * 60 * 60
)
return {"access_token":access_token, "token_type": "bearer"}
async def get_current_user(token:str = Depends(oauth2_schema)) -> UserOut: