fix: makefile:install, auth token logic
This commit is contained in:
@@ -26,6 +26,8 @@ from api.services.auth import authenticate_user
|
||||
|
||||
from api.db.logic.auth import add_new_refresh_token,upgrade_old_refresh_token
|
||||
|
||||
from api.db.logic.account import get_user_login
|
||||
|
||||
from api.schemas.endpoints.auth import Auth
|
||||
|
||||
api_router = APIRouter(
|
||||
@@ -91,7 +93,6 @@ async def login_for_access_token(
|
||||
|
||||
refresh_token_expires_time = datetime.now(timezone.utc) + refresh_token_expires
|
||||
|
||||
await upgrade_old_refresh_token(connection,user)
|
||||
|
||||
await add_new_refresh_token(connection,refresh_token,refresh_token_expires_time,user)
|
||||
|
||||
@@ -107,8 +108,9 @@ async def login_for_access_token(
|
||||
|
||||
|
||||
@api_router.post("/refresh")
|
||||
def refresh(
|
||||
async def refresh(
|
||||
request: Request,
|
||||
connection: AsyncConnection = Depends(get_connection_dep),
|
||||
Authorize: AuthJWT = Depends()):
|
||||
"""Обновляет access токен."""
|
||||
|
||||
@@ -122,22 +124,27 @@ def refresh(
|
||||
try:
|
||||
|
||||
Authorize.jwt_refresh_token_required()
|
||||
current_user = Authorize.get_jwt_subject()
|
||||
print(current_user)
|
||||
|
||||
except Exception as e:
|
||||
|
||||
await upgrade_old_refresh_token(connection,current_user)
|
||||
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Invalid refresh token",
|
||||
)
|
||||
|
||||
|
||||
current_user = Authorize.get_jwt_subject()
|
||||
|
||||
access_token_expires = timedelta(minutes=get_settings().ACCESS_TOKEN_EXPIRE_MINUTES)
|
||||
|
||||
new_access_token = Authorize.create_access_token(
|
||||
subject=current_user, expires_time=access_token_expires
|
||||
)
|
||||
|
||||
Authorize.set_access_cookies(new_access_token)
|
||||
|
||||
return {"msg": "The token has been refresh"}
|
||||
return {
|
||||
"access_token": new_access_token,
|
||||
# "access_token_expires": access_token_expires_time,
|
||||
# "refresh_token": refresh_token,
|
||||
# "refresh_token_expires": refresh_token_expires_time
|
||||
}
|
||||
|
Reference in New Issue
Block a user