Version: 0.9.66.dev.260504
后端: 1. 阶段 2 user/auth 服务边界落地,新增 `cmd/userauth` go-zero zrpc 服务、`services/userauth` 核心实现、gateway user API/zrpc client 与 shared contracts/ports,迁移注册、登录、刷新 token、登出、JWT、黑名单和 token 额度治理 2. gateway 与启动装配切流,`cmd/all` 只保留边缘路由、鉴权和轻量组合,通过 userauth zrpc 访问核心用户能力;拆分 MySQL/Redis 初始化与 AutoMigrate 边界,`userauth` 自迁 `users` 和 token 记账幂等表,`all` 不再迁用户表 3. 清退 Gin 单体旧 user/auth DAO、model、service、router、middleware 和 JWT handler,并同步调整 agent/schedule/cache/outbox 相关调用依赖 4. 补齐 refresh token 防并发重放、MySQL 幂等 token 记账、额度 `>=` 拦截和 RPC 错误映射,避免重复记账与内部错误透出 文档: 1. 新增《学习计划论坛与Token商店PRD》
This commit is contained in:
46
backend/shared/ports/userauth.go
Normal file
46
backend/shared/ports/userauth.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package ports
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
contracts "github.com/LoveLosita/smartflow/backend/shared/contracts/userauth"
|
||||
)
|
||||
|
||||
// UserCommandClient 是用户入口依赖的 user/auth 命令能力集合。
|
||||
// 职责边界:
|
||||
// 1. 只描述注册、登录、刷新、登出这些入口能力;
|
||||
// 2. 不暴露 DAO、Redis、JWT 签发细节;
|
||||
// 3. 具体通信协议由 adapter 实现,调用方只按 res, err 语义处理。
|
||||
type UserCommandClient interface {
|
||||
Register(ctx context.Context, req contracts.RegisterRequest) (*contracts.RegisterResponse, error)
|
||||
Login(ctx context.Context, req contracts.LoginRequest) (*contracts.Tokens, error)
|
||||
RefreshToken(ctx context.Context, req contracts.RefreshTokenRequest) (*contracts.Tokens, error)
|
||||
Logout(ctx context.Context, accessToken string) error
|
||||
}
|
||||
|
||||
// AccessTokenValidator 是边缘鉴权依赖的最小接口。
|
||||
// 职责边界:只校验 access token 并返回后续业务所需的最小身份信息。
|
||||
type AccessTokenValidator interface {
|
||||
ValidateAccessToken(ctx context.Context, accessToken string) (*contracts.ValidateAccessTokenResponse, error)
|
||||
}
|
||||
|
||||
// TokenQuotaChecker 是 agent/chat 入口做额度门禁时依赖的最小接口。
|
||||
// 职责边界:只判断当前用户是否允许继续消费 token,不负责 token 入账。
|
||||
type TokenQuotaChecker interface {
|
||||
CheckTokenQuota(ctx context.Context, userID int) (*contracts.CheckTokenQuotaResponse, error)
|
||||
}
|
||||
|
||||
// TokenUsageAdjuster 是业务链路回写 token 账本时依赖的最小接口。
|
||||
// 职责边界:只做 token 账本增量调整,不承载鉴权与登录逻辑。
|
||||
type TokenUsageAdjuster interface {
|
||||
AdjustTokenUsage(ctx context.Context, req contracts.AdjustTokenUsageRequest) (*contracts.CheckTokenQuotaResponse, error)
|
||||
}
|
||||
|
||||
// UserAuthClient 组合当前阶段需要的 user/auth 能力。
|
||||
// 职责边界:作为统一装配口径,避免 gateway 和 core service 各自维护一份接口。
|
||||
type UserAuthClient interface {
|
||||
UserCommandClient
|
||||
AccessTokenValidator
|
||||
TokenQuotaChecker
|
||||
TokenUsageAdjuster
|
||||
}
|
||||
Reference in New Issue
Block a user