asyncio style refactoring
This commit is contained in:
@@ -11,7 +11,7 @@ oauth2_schema=OAuth2PasswordBearer(tokenUrl="/protected/token", refreshUrl="/pro
|
||||
@router.post("/token")
|
||||
async def get_access_token(request: Request,response:Response,auth:CurrentUserService=Depends(auth_service), form_data:OAuth2PasswordRequestForm=Depends())->dict: # noqa: B008
|
||||
|
||||
access_token, refresh_token=auth.login(form_data_email=form_data.username, form_data_password=form_data.password, request=request)
|
||||
access_token, refresh_token=await auth.login(form_data_email=form_data.username, form_data_password=form_data.password, request=request)
|
||||
|
||||
response.set_cookie(
|
||||
key="refresh_token",
|
||||
@@ -27,7 +27,7 @@ async def get_access_token(request: Request,response:Response,auth:CurrentUserSe
|
||||
@router.post("/refresh")
|
||||
async def get_refresh_token(request:Request,response:Response, refresh_token: str = Cookie(), auth:CurrentUserService=Depends(auth_service))->dict: # noqa: B008
|
||||
|
||||
access_token, refresh_token= auth.refresh_token(refresh_token=refresh_token,request=request)
|
||||
access_token, refresh_token= await auth.refresh_token(refresh_token=refresh_token,request=request)
|
||||
|
||||
response.set_cookie(
|
||||
key="refresh_token",
|
||||
@@ -42,13 +42,13 @@ async def get_refresh_token(request:Request,response:Response, refresh_token: st
|
||||
|
||||
|
||||
async def get_current_user(token:str = Depends(oauth2_schema), auth:CurrentUserService=Depends(auth_service)) -> UserOut: # noqa: B008
|
||||
return UserOut.model_validate(auth.get_current_user(token))
|
||||
return UserOut.model_validate(await auth.get_current_user(token))
|
||||
|
||||
|
||||
@router.get("/logout")
|
||||
async def logout(response:Response,refresh_token: str = Cookie(),auth:CurrentUserService=Depends(auth_service),current_user:UserOut=Depends(get_current_user))->bool: # noqa: B008
|
||||
response.delete_cookie("refresh_token")
|
||||
return auth.logout(refresh_token)
|
||||
return await auth.logout(refresh_token)
|
||||
|
||||
@router.get("")
|
||||
async def protected(current_user:UserOut=Depends(get_current_user))->dict: # noqa: B008
|
||||
|
||||
Reference in New Issue
Block a user