Documentation
¶
Index ¶
- Variables
- func GenerateAdminToken(userID uint, username string) (string, error)
- func GenerateToken(userID uint, username, role string) (string, error)
- func IsTokenRevoked(ctx context.Context, token string) bool
- func RefreshToken(ctx context.Context, tokenString string) (string, error)
- func RevokeToken(ctx context.Context, token string, remaining time.Duration)
- func SessionExpiry() time.Duration
- func SetBlacklistRedis(rdb *redis.Client)
- func SetEpochLoader(fn func(userID uint) int)
- func SetJWTSecret(secret string)
- func SetSessionExpiry(d time.Duration)
- type Claims
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func GenerateAdminToken ¶
GenerateAdminToken 生成管理员 token
func GenerateToken ¶
GenerateToken 生成 JWT token
func IsTokenRevoked ¶
IsTokenRevoked 查询 token 是否已注销。 Redis 查询失败时回退内存兜底(与 RevokeToken 的降级写配对,故障窗口内 写入内存的吊销仍可被查到)。
func RefreshToken ¶
RefreshToken 刷新 token。已注销(黑名单)的 token 拒绝刷新, 堵住"登出后旧 token 仍可换新"的撤销绕过(设计文档 §9.6)。
轮换语义(2026-10-05 审计 P1 修复):签发新 token 的同时把旧 token 按剩余 有效期加入黑名单——否则被盗 token 可与真用户并行使用到自然过期,且每次 刷新都无法止损。
func RevokeToken ¶
RevokeToken 注销 token(至其自然过期前一直拦截)。 Redis 故障时降级写内存兜底(2026-10-05 审计 P2:此前 Set 错误被吞、查询 fail-open,Redis 抖动窗口内已注销 token 静默恢复可用)。
func SetBlacklistRedis ¶
SetBlacklistRedis 注入 Redis(bootstrap 调用;nil = 纯内存模式)。 nil 归一化:typed-nil 接口会骗过内存模式守卫(!= nil 判真)。
func SetEpochLoader ¶
SetEpochLoader 注入纪元加载器(bootstrap 调用一次;nil 关闭)。
func SetSessionExpiry ¶
SetSessionExpiry 设置会话时长;<=0 视为非法,保留原值。 仅影响新签发的 token,已签发会话到自然过期。
Types ¶
Click to show internal directories.
Click to hide internal directories.