netx/netx_api/auth_schemas.py
oliver 633a9d55bd Harden auth scopes, SQL/WebCRT gates, and per-install JWT secrets.
Add capability RBAC, Alembic bootstrap, optional worker schedulers, and close public docs by default so lab installs stay usable without shared signing keys.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-02 16:24:34 +08:00

39 lines
1.3 KiB
Python

"""Pydantic schemas for auth / users / audit / API tokens."""
from __future__ import annotations
from pydantic import BaseModel, Field
class LoginRequest(BaseModel):
username: str = Field(min_length=1, max_length=64)
password: str = Field(min_length=1, max_length=256)
class ChangePasswordRequest(BaseModel):
old_password: str = Field(min_length=1, max_length=256)
new_password: str = Field(min_length=6, max_length=256)
class UserCreateRequest(BaseModel):
username: str = Field(min_length=2, max_length=64)
password: str = Field(min_length=6, max_length=256)
role: str = Field(default="user")
scopes: list[str] | None = None
class UserUpdateRequest(BaseModel):
is_active: bool | None = None
role: str | None = None
password: str | None = Field(default=None, min_length=6, max_length=256)
scopes: list[str] | None = None
class ApiTokenCreateRequest(BaseModel):
name: str = Field(default="default", max_length=128)
# Days until expiry; 0 / null = never expires.
expires_in_days: int | None = Field(default=90, ge=0, le=3650)
# Admin may create a token for another user; others ignored / forced to self.
user_id: str | None = None
# Capability subset; empty inherits owner scopes.
scopes: list[str] | None = None