Buckets:

download
raw
1.06 kB
from fastapi import APIRouter
from pydantic import BaseModel
from leggen.errors import AuthenticationError
from leggen.utils.auth import create_access_token, verify_password
from leggen.utils.config import config
router = APIRouter(prefix="/auth", tags=["auth"])
class LoginRequest(BaseModel):
username: str
password: str
class LoginResponse(BaseModel):
access_token: str
token_type: str = "bearer"
@router.post("/login", response_model=LoginResponse)
async def login(request: LoginRequest) -> LoginResponse:
"""Authenticate with username and password, returns JWT token."""
auth_cfg = config.auth_config
if request.username != auth_cfg["username"] or not verify_password(
request.password, auth_cfg["password_hash"]
):
raise AuthenticationError("Invalid username or password.")
token = create_access_token(
username=request.username,
secret=auth_cfg["jwt_secret"],
expires_minutes=auth_cfg.get("jwt_expiry_minutes", 60),
)
return LoginResponse(access_token=token)

Xet Storage Details

Size:
1.06 kB
·
Xet hash:
fa8ead6db3c279dc44fea5916b760af184aff53a30a49540eb5e068ce6eb9567

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.