149c35c21b
替掉"裸 X-User-ID 头当身份"的临时方案,落地无状态 JWT 鉴权后端: - internal/auth:JWT 签发/校验(HS256,密钥 env JWT_SECRET,仅接受 HMAC 防 alg 混淆) + bcrypt 密码哈希/校验。纯包,含单测。 - User 模型加 Name + PasswordHash(json:"-" 不外泄);store 加 CreateUser/GetUserByEmail/ GetUserByID(邮箱唯一冲突 → ErrUserExists)。 - handler/auth:POST /auth/register(建用户+签发)· POST /auth/login(校验+签发, 用户不存在与密码错同一文案防枚举)· GET /auth/me。 - middleware/auth:解析 Bearer JWT,校验通过把已验证 userID 注入上下文(非阻断)。 - userID(c) 改为优先取 JWT 注入的 uid,兜底 X-User-ID 头(前端尚未接登录,保持可用)。 验证: - 单测:JWT 签发/解析往返、过期拒绝、篡改/非法拒绝、bcrypt 哈希校验。 - 实跑(nats+pg+gateway):注册→token+user(无密码)、重复注册 409、错密码 401、 /auth/me 带 token 200 / 无 token 401;owner 隔离改用已验证 uid —— 带 token 建的库 匿名/伪造 header 都看不到(JWT 用户数据归于雪花 id,header 无法臆测)。 片 2 待做:前端登录页 + 存令牌带 Bearer + 处理 401 + 去掉 header 兜底 + 保护路由。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
71 lines
2.8 KiB
Modula-2
71 lines
2.8 KiB
Modula-2
module github.com/sundynix/sundynix-gateway
|
|
|
|
go 1.25.0
|
|
|
|
require (
|
|
github.com/bwmarrin/snowflake v0.3.0
|
|
github.com/gin-gonic/gin v1.10.0
|
|
github.com/minio/minio-go/v7 v7.2.0
|
|
github.com/redis/go-redis/v9 v9.20.0
|
|
github.com/sundynix/sundynix-shared v0.0.0
|
|
gorm.io/driver/postgres v1.6.0
|
|
gorm.io/gorm v1.31.1
|
|
)
|
|
|
|
replace github.com/sundynix/sundynix-shared => ../sundynix-shared
|
|
|
|
require (
|
|
github.com/bytedance/gopkg v0.1.3 // indirect
|
|
github.com/bytedance/sonic v1.15.0 // indirect
|
|
github.com/bytedance/sonic/loader v0.5.0 // indirect
|
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
|
github.com/cloudwego/base64x v0.1.6 // indirect
|
|
github.com/dustin/go-humanize v1.0.1 // indirect
|
|
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
|
github.com/go-playground/locales v0.14.1 // indirect
|
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
|
github.com/go-playground/validator/v10 v10.20.0 // indirect
|
|
github.com/goccy/go-json v0.10.2 // indirect
|
|
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
|
|
github.com/google/uuid v1.6.0 // indirect
|
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
|
github.com/jackc/pgx/v5 v5.6.0 // indirect
|
|
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
|
github.com/jinzhu/now v1.1.5 // indirect
|
|
github.com/json-iterator/go v1.1.12 // indirect
|
|
github.com/klauspost/compress v1.18.6 // indirect
|
|
github.com/klauspost/cpuid/v2 v2.2.11 // indirect
|
|
github.com/klauspost/crc32 v1.3.0 // indirect
|
|
github.com/kr/text v0.2.0 // indirect
|
|
github.com/leodido/go-urn v1.4.0 // indirect
|
|
github.com/mattn/go-isatty v0.0.20 // indirect
|
|
github.com/minio/crc64nvme v1.1.1 // indirect
|
|
github.com/minio/md5-simd v1.1.2 // indirect
|
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
|
github.com/nats-io/nats.go v1.37.0 // indirect
|
|
github.com/nats-io/nkeys v0.4.7 // indirect
|
|
github.com/nats-io/nuid v1.0.1 // indirect
|
|
github.com/pelletier/go-toml/v2 v2.3.1 // indirect
|
|
github.com/philhofer/fwd v1.2.0 // indirect
|
|
github.com/rs/xid v1.6.0 // indirect
|
|
github.com/tinylib/msgp v1.6.1 // indirect
|
|
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
|
github.com/ugorji/go/codec v1.2.12 // indirect
|
|
github.com/zeebo/xxh3 v1.1.0 // indirect
|
|
go.uber.org/atomic v1.11.0 // indirect
|
|
go.yaml.in/yaml/v3 v3.0.4 // indirect
|
|
golang.org/x/arch v0.11.0 // indirect
|
|
golang.org/x/crypto v0.53.0 // indirect
|
|
golang.org/x/net v0.55.0 // indirect
|
|
golang.org/x/sync v0.21.0 // indirect
|
|
golang.org/x/sys v0.46.0 // indirect
|
|
golang.org/x/text v0.38.0 // indirect
|
|
google.golang.org/protobuf v1.36.10 // indirect
|
|
gopkg.in/ini.v1 v1.67.2 // indirect
|
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
|
)
|