Files
zogo/jwtx/README.md
T

24 lines
742 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# jwtx
轻量 HMAC-SHA256 令牌(JWT 风格,无第三方依赖),用于登录态/服务间鉴权。
## 用法
```go
import "git.zeroonesoft.cn/golib/zogo/jwtx"
token, err := jwtx.Sign(uid, 3600) // 签发,TTL 秒
claims, err := jwtx.Parse(token) // 校验签名+过期,返回 *Claims{Uid, Exp, Msg}
```
## 格式
`base64url(payload).base64url(hmac-sha256(payload))`,两段式(无 header 段),payload 为
`Claims` JSON。
## 注意
- **签名密钥当前硬编码在包内**(`zo-maintain-jwt-secret-2026`)。仅适用于内网/测试场景;
用于生产鉴权前应改为注入式(加 `SetSecret` 或从环境读取)。
- 过期校验在 `Parse` 内完成(`Exp` 与当前时间比较)。