feat: 更新认证逻辑,支持通过openid查找或创建用户,并调整JWT负载字段

This commit is contained in:
2026-05-27 01:49:23 +08:00
parent 3506731061
commit 80904e65d8
6 changed files with 641 additions and 16 deletions

View File

@@ -31,13 +31,14 @@ class TokenResponse(BaseModel):
def _build_token(user: User) -> str:
"""生成自包含 JWT:sub + openid + mobile"""
"""生成自包含 JWT:uid + openid + phone(兼容外部 token 格式)"""
expire = datetime.now(timezone.utc) + timedelta(days=30)
payload = {
"sub": str(user.id),
"uid": str(user.id),
"openid": user.openid,
"mobile": user.phone or "",
"phone": user.phone or "",
"exp": expire,
"iss": "localhost",
}
return jwt.encode(payload, settings.jwt_secret_key, algorithm=settings.jwt_algorithm)