feat: add password login and bearer sessions

- Argon2id password hashes, KDF in a thread with its own limit
- POST /auth/sessions with Basic, DELETE /auth/sessions/current
- Bearer sessions in PostgreSQL, X-User-Id ignored
- migration drops lab 1 data without passwords
- student-tests on tokens, sessions spec and synced specs

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-01 18:50:42 +03:00
co-authored by Claude Opus 5.5
parent ee2643d21e
commit ae4154eaf5
68 changed files with 2946 additions and 314 deletions
+2
View File
@@ -1,6 +1,7 @@
from .chat import Chat, ChatPage, CreateChat
from .common import Error, ErrorBody, ErrorCode, Health
from .message import CreateMessage, Message, MessagePage
from .session import Session
from .user import CreateUser, User
__all__ = [
@@ -15,5 +16,6 @@ __all__ = [
"Health",
"Message",
"MessagePage",
"Session",
"User",
]
+15
View File
@@ -0,0 +1,15 @@
from typing import Literal
from pydantic import BaseModel, ConfigDict
from src.api.schemas.common import UtcDatetime
from src.api.schemas.user import User
class Session(BaseModel):
model_config = ConfigDict(from_attributes=True)
token: str
token_type: Literal["Bearer"] = "Bearer"
expires_at: UtcDatetime
user: User
+8
View File
@@ -6,6 +6,8 @@ from src.api.schemas.common import NonBlankStr, UtcDatetime
from src.utils.constants import (
DISPLAY_NAME_MAX_LENGTH,
DISPLAY_NAME_MIN_LENGTH,
PASSWORD_MAX_LENGTH,
PASSWORD_MIN_LENGTH,
USERNAME_PATTERN,
)
@@ -18,6 +20,12 @@ class CreateUser(BaseModel):
min_length=DISPLAY_NAME_MIN_LENGTH,
max_length=DISPLAY_NAME_MAX_LENGTH,
)
# длина в code points; значение не обрезается и не нормализуется
password: NonBlankStr = Field(
min_length=PASSWORD_MIN_LENGTH,
max_length=PASSWORD_MAX_LENGTH,
json_schema_extra={"writeOnly": True},
)
class User(BaseModel):