ailane-n27by1/endpoints/auth.get.py
2025-03-21 14:37:05 +01:00

28 lines
687 B
Python

from fastapi import APIRouter, HTTPException
users = [
{
"username": "admin",
"password": "securepassword"
}
]
router = APIRouter()
@router.get("/auth")
async def authenticate_user(
username: str = "admin",
password: str = "securepassword"
):
"""authenticates the user"""
user = next((u for u in users if u["username"] == username), None)
if not user or user["password"] != password:
raise HTTPException(status_code=400, detail="Invalid credentials")
return {
"method": "GET",
"_verb": "get",
"message": "Authentication successful",
"user": username,
"token": "dummy_jwt_token_456"
}