MCPcopy
hub / github.com/AstrBotDevs/AstrBot / require_dashboard_user

Function require_dashboard_user

astrbot/dashboard/api/auth.py:85–107  ·  view source on GitHub ↗
(request: Request)

Source from the content-addressed store, hash-verified

83
84
85async def require_dashboard_user(request: Request) -> str:
86 if username := _get_dashboard_state_username(request):
87 return username
88
89 token = _extract_dashboard_jwt(request)
90 if not token:
91 raise ApiError("未授权", status_code=401)
92
93 try:
94 payload = jwt.decode(
95 token,
96 request.app.state.jwt_secret,
97 algorithms=["HS256"],
98 )
99 except jwt.ExpiredSignatureError as exc:
100 raise ApiError("Token 过期", status_code=401) from exc
101 except jwt.InvalidTokenError as exc:
102 raise ApiError("Token 无效", status_code=401) from exc
103
104 username = payload.get("username")
105 if not isinstance(username, str) or not username.strip():
106 raise ApiError("Token 无效", status_code=401)
107 return username
108
109
110async def _require_api_key_scope(

Callers

nothing calls this directly

Calls 5

ApiErrorClass · 0.90
_extract_dashboard_jwtFunction · 0.85
decodeMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected