This commit is contained in:
2026-08-14 12:13:02 +08:00
parent 0e62930c64
commit 285fa01471
71 changed files with 1805 additions and 746 deletions
+5
View File
@@ -31,6 +31,11 @@ func GenerateToken(secret string, uid int64, role string, expireSeconds int) (st
return claims.SignedString([]byte(secret))
}
// Secret 鉴权密钥(config.yml auth.secret),token 签发与解析共用入口。
func Secret(ctx context.Context) string {
return g.Cfg().MustGet(ctx, "auth.secret").String()
}
// ParseToken 校验并解析 token,返回 uid 与 role。
func ParseToken(secret, tokenString string) (uid int64, role string, err error) {
token, err := jwt.Parse(tokenString, func(t *jwt.Token) (any, error) {