Skip to content

文件:core/auth.py

负责 JWT 的生成与解析。

函数定义与行为

generate_token(request: Request, user_id: str, level: int) -> str

生成 JWT,载荷字段:

  • uid: 玩家 ID
  • lvl: 可访问最大关卡等级
  • fgp: 指纹 hash(由 generate_fingerprint 生成)
  • iat: 签发时间戳
  • exp: 过期时间戳

过期时间由 config/token_expire_hours 决定,签名算法 HS256

decode_token(token: str) -> dict

使用 config/secret_key 解码 token,若过期或签名不匹配会抛出异常。