feat(auth): support trusted device (#52)

New API to maintain sessions and devices:

- GET /api/private/admin/sessions
- DELETE /api/private/admin/sessions/{session_id}
- GET /api/private/admin/trusted-devices
- DELETE /api/private/admin/trusted-devices/{device_id}

Auth:

web clients request `/oauth/token` and `/api/v2/session/verify` with `X-UUID` header to save the client as trusted device.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
MingxuanGame
2025-10-03 11:26:43 +08:00
committed by GitHub
parent f34ed53a55
commit 40670c094b
28 changed files with 897 additions and 1456 deletions

View File

@@ -1,5 +1,6 @@
from __future__ import annotations
from dataclasses import dataclass
from datetime import UTC, datetime
from app.models.score import GameMode
@@ -53,3 +54,33 @@ class CurrentUserAttributes(BaseModel):
can_new_comment: bool | None = None
can_new_comment_reason: str | None = None
pin: PinAttributes | None = None
@dataclass
class UserAgentInfo:
raw_ua: str = ""
browser: str | None = None
version: str | None = None
os: str | None = None
platform: str | None = None
is_mobile: bool = False
is_tablet: bool = False
is_pc: bool = False
is_client: bool = False
@property
def displayed_name(self) -> str:
parts = []
if self.browser:
parts.append(self.browser)
if self.version:
parts.append(self.version)
if self.os:
if parts:
parts.append(f"on {self.os}")
else:
parts.append(self.os)
return " ".join(parts) if parts else "Unknown"
def __str__(self) -> str:
return self.displayed_name