auth_context.py 671 B

12345678910111213141516171819202122232425262728
  1. """Bearer认证上下文骨架;B1不实现JWT验签和用户查询。"""
  2. from __future__ import annotations
  3. from dataclasses import dataclass
  4. from flask import g
  5. from dms.common.enums import RoleCode, SecurityLevel
  6. @dataclass(frozen=True, slots=True)
  7. class AuthContext:
  8. user_id: int
  9. username: str
  10. real_name: str
  11. organization_id: int | None
  12. organization_name: str | None
  13. role_code: RoleCode
  14. security_level: SecurityLevel
  15. auth_version: int
  16. def get_auth_context() -> AuthContext:
  17. context = getattr(g, "dms_auth_context", None)
  18. if context is None:
  19. raise RuntimeError("认证上下文尚未建立")
  20. return context