response cookie
This commit is contained in:
parent
4787a341b8
commit
a45d9f0743
@ -2,6 +2,7 @@ from datetime import datetime, timedelta
|
||||
|
||||
from typing import Annotated
|
||||
from fastapi import Depends, FastAPI, HTTPException, status, APIRouter
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
||||
from ..dependencies import users_token
|
||||
from ..models import token
|
||||
@ -9,7 +10,7 @@ from ..models import token
|
||||
router = APIRouter()
|
||||
ACCESS_TOKEN_EXPIRE_MINUTES = 30
|
||||
|
||||
@router.post("/token", response_model=token.Token, tags=["token"])
|
||||
@router.post("/token", tags=["token"])
|
||||
async def login_for_access_token(
|
||||
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
|
||||
):
|
||||
@ -24,4 +25,7 @@ async def login_for_access_token(
|
||||
access_token = users_token.create_access_token(
|
||||
data={"sub": user.username}, expires_delta=access_token_expires
|
||||
)
|
||||
return {"access_token": access_token, "token_type": "bearer"}
|
||||
content = {"message": "Access token generated"}
|
||||
response = JSONResponse(content=content)
|
||||
response.set_cookie(key="jwt", value=access_token)
|
||||
return response
|
Loading…
x
Reference in New Issue
Block a user