feat: inelegant and buggy version of auth
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from datetime import timedelta, timezone, datetime
|
||||
from typing import Annotated
|
||||
from fastapi import Depends, HTTPException, status
|
||||
from fastapi import Depends, HTTPException, Response, status
|
||||
from pydantic import BaseModel
|
||||
import jwt
|
||||
from jwt.exceptions import InvalidTokenError
|
||||
@@ -102,7 +102,7 @@ async def get_current_active_user(
|
||||
|
||||
|
||||
async def login_for_access_token(
|
||||
form_data: Annotated[OAuth2PasswordRequestForm, Depends()],
|
||||
form_data: Annotated[OAuth2PasswordRequestForm, Depends()], response: Response
|
||||
) -> Token:
|
||||
user = authenticate_user(form_data.username, form_data.password)
|
||||
if not user:
|
||||
@@ -115,6 +115,9 @@ async def login_for_access_token(
|
||||
access_token = create_access_token(
|
||||
data={"sub": user.username}, expires_delta=access_token_expires
|
||||
)
|
||||
response.set_cookie(
|
||||
"Authorization", value=f"Bearer {access_token}", httponly=True, samesite="none"
|
||||
)
|
||||
return Token(access_token=access_token, token_type="bearer")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user