feat: 更新认证逻辑,支持通过openid查找或创建用户,并调整JWT负载字段
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user