refactor(server): 移除鉴权并归档遗留路由至 legacy/
- 删除 auth.py 与 deps.py,各路由去除 get_current_user 依赖 - collection.py 更名为 materials.py,冻结链路(ozon/publish/shops/categories)移入 legacy/ - 扩展默认生图服务端口并入 8800 并自动迁移旧配置,水印默认文案改为 Panda Store - 新增 docs/v2.1/backend-structure.md 后端结构盘点文档
This commit is contained in:
+4
-23
@@ -1,35 +1,16 @@
|
||||
"""JWT 鉴权 + 店铺凭证 AES-GCM 加解密。"""
|
||||
"""店铺凭证 AES-GCM 加解密(shops/categories/publish 冻结链路使用)。
|
||||
|
||||
鉴权(JWT/APP_TOKEN)已按 V2.1 决策移除,后续加账户体系时再引入。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import base64
|
||||
import hashlib
|
||||
import os
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
import jwt
|
||||
|
||||
from config import get_settings
|
||||
|
||||
|
||||
# ── JWT ──
|
||||
|
||||
def create_access_token(subject: str = "app") -> tuple[str, int]:
|
||||
"""签发 JWT。返回 (token, 过期 epoch 秒)。"""
|
||||
settings = get_settings()
|
||||
expires = datetime.now(timezone.utc) + timedelta(minutes=settings.jwt_expire_minutes)
|
||||
payload = {"sub": subject, "exp": expires}
|
||||
token = jwt.encode(payload, settings.secret_key, algorithm="HS256")
|
||||
return token, int(expires.timestamp())
|
||||
|
||||
|
||||
def decode_token(token: str) -> dict:
|
||||
"""校验并解析 JWT;失败抛 jwt.PyJWTError。"""
|
||||
settings = get_settings()
|
||||
return jwt.decode(token, settings.secret_key, algorithms=["HS256"])
|
||||
|
||||
|
||||
# ── AES-GCM 店铺凭证加密 ──
|
||||
|
||||
def _derive_key() -> bytes:
|
||||
settings = get_settings()
|
||||
return hashlib.sha256(settings.secret_key.encode("utf-8")).digest()
|
||||
|
||||
Reference in New Issue
Block a user