| 12345678910111213141516171819202122232425262728 |
- """Bearer认证上下文骨架;B1不实现JWT验签和用户查询。"""
- from __future__ import annotations
- from dataclasses import dataclass
- from flask import g
- from dms.common.enums import RoleCode, SecurityLevel
- @dataclass(frozen=True, slots=True)
- class AuthContext:
- user_id: int
- username: str
- real_name: str
- organization_id: int | None
- organization_name: str | None
- role_code: RoleCode
- security_level: SecurityLevel
- auth_version: int
- def get_auth_context() -> AuthContext:
- context = getattr(g, "dms_auth_context", None)
- if context is None:
- raise RuntimeError("认证上下文尚未建立")
- return context
|