mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: init auth cookies
This commit is contained in:
parent
8cc727e309
commit
9479a4b127
5 changed files with 27 additions and 15 deletions
|
|
@ -1,9 +1,9 @@
|
|||
from fastapi import Depends, FastAPI, APIRouter, HTTPException, status
|
||||
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
|
||||
from pydantic import BaseModel
|
||||
from fastapi import Depends, APIRouter, HTTPException, status
|
||||
from fastapi.security import OAuth2PasswordRequestForm
|
||||
from src.services.auth import *
|
||||
from src.services.users import *
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import timedelta
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
|
@ -24,4 +24,8 @@ async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends(
|
|||
access_token = create_access_token(
|
||||
data={"sub": user.username}, expires_delta=access_token_expires
|
||||
)
|
||||
return {"access_token": access_token, "token_type": "bearer"}
|
||||
|
||||
response = JSONResponse(content={"access_token" : access_token ,"token_type": "bearer"})
|
||||
response.set_cookie(key="user_token", value=access_token, httponly=True, expires="3600",secure=True)
|
||||
|
||||
return response
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue