This commit is contained in:
2025-03-06 22:00:52 +01:00
parent 4669774cc3
commit 221bd1e244
3 changed files with 1 additions and 78 deletions

View File

@@ -11,27 +11,6 @@ from ..models import token, users
router = APIRouter()
ACCESS_TOKEN_EXPIRE_MINUTES = 30
@router.post("/oauth/{provider}", tags=["token"])
async def oauth_login(provider: str, token: str):
"""Handles OAuth login via Google/Facebook."""
user = await users_token.authenticate_oauth(provider, token)
if not user:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Invalid authentication"
)
access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
access_token = users_token.create_access_token(
data={"sub": user.username}, expires_delta=access_token_expires
)
content = {"roles": user.roles, "message": "OAuth login successful"}
response = JSONResponse(content=content)
response.set_cookie(key="access_token", value=f"Bearer {access_token}", httponly=True)
return response
@router.post("/token", tags=["token"])
async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]):