535d97a70c
17-table PostgreSQL schema with full Chinese column comments, FastAPI project structure (admin/common/modules), DSL rule files, and schema migration scripts.
24 lines
629 B
Python
24 lines
629 B
Python
"""JWT 鉴权工具。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
import jwt
|
|
from fastapi import Request
|
|
|
|
from fastapi_admin.config import JWT_SECRET_KEY, JWT_ALGORITHM
|
|
|
|
|
|
def verify_access_token(RequestObj: Request) -> dict[str, Any]:
|
|
"""验证 JWT access token 并返回 payload。"""
|
|
auth = RequestObj.headers.get("Authorization", "")
|
|
if not auth.startswith("Bearer "):
|
|
return {}
|
|
token = auth.removeprefix("Bearer ").strip()
|
|
try:
|
|
payload = jwt.decode(token, JWT_SECRET_KEY, algorithms=[JWT_ALGORITHM])
|
|
return payload
|
|
except jwt.PyJWTError:
|
|
return {}
|