dak.c2s/backend/app/schemas/auth.py
CCS Admin 518de3da27 feat: auth system — login, register, refresh, MFA, domain whitelist
Add complete authentication layer:
- Pydantic v2 schemas for auth requests/responses and user representation
- Auth service with login (account locking, MFA), registration (invitation
  tokens + domain whitelist), token management, MFA setup/activation, and
  password change
- FastAPI router with 8 endpoints: login, register, refresh, logout,
  mfa/setup, mfa/verify, change-password, me
- Router registered in main.py under /api/auth

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-24 07:46:04 +00:00

64 lines
1.4 KiB
Python

"""Pydantic v2 schemas for authentication endpoints."""
from typing import Optional
from pydantic import BaseModel, EmailStr
from app.schemas.user import UserResponse
class LoginRequest(BaseModel):
"""Credentials submitted to POST /login."""
email: EmailStr
password: str
mfa_code: Optional[str] = None
class TokenResponse(BaseModel):
"""Returned on successful login or token refresh."""
access_token: str
refresh_token: str
token_type: str = "bearer"
user: UserResponse
class RegisterRequest(BaseModel):
"""Self-service registration (requires invitation token or whitelisted domain)."""
username: str
email: EmailStr
password: str
invitation_token: Optional[str] = None
class RefreshRequest(BaseModel):
"""Request body for POST /refresh."""
refresh_token: str
class MFASetupResponse(BaseModel):
"""Returned when a user initiates MFA setup."""
secret: str
qr_uri: str
class MFAVerifyRequest(BaseModel):
"""6-digit TOTP code + secret submitted to activate MFA.
The *secret* was returned by ``/mfa/setup`` and must be echoed back so
the server can verify the code before persisting.
"""
secret: str
code: str
class ChangePasswordRequest(BaseModel):
"""Request body for changing the authenticated user's password."""
old_password: str
new_password: str