update
This commit is contained in:
@ -39,16 +39,10 @@ func NewManager(secret string, expireHours int) *Manager {
|
||||
}
|
||||
}
|
||||
|
||||
// Generate 签发令牌。
|
||||
func (m *Manager) Generate(userID uint32, username, email string) (string, error) {
|
||||
claims := jwtlib.MapClaims{
|
||||
"uid": userID,
|
||||
"username": username,
|
||||
"email": email,
|
||||
"exp": time.Now().Add(m.expire).Unix(),
|
||||
}
|
||||
return jwtlib.NewWithClaims(jwtlib.SigningMethodHS256, claims).SignedString(m.secret)
|
||||
}
|
||||
// 注:Generate(签发令牌)已随注册 / 登录接口一并移除——当前服务没有任何签发入口,
|
||||
// 只保留 Parse 供 middleware.Auth 校验既有令牌。
|
||||
// 将来接入登录时恢复:构造 jwtlib.MapClaims{"uid","username","email","exp"},
|
||||
// 再用 jwtlib.NewWithClaims(jwtlib.SigningMethodHS256, claims).SignedString(m.secret) 签名即可。
|
||||
|
||||
// Parse 校验并解析令牌。
|
||||
func (m *Manager) Parse(tokenStr string) (*Claims, error) {
|
||||
|
||||
Reference in New Issue
Block a user