登录功能完成
This commit is contained in:
25
pkg/token/jwt.go
Normal file
25
pkg/token/jwt.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package token
|
||||
|
||||
import (
|
||||
"github.com/golang-jwt/jwt/v4"
|
||||
"mc-client-updater-server/pkg/conf"
|
||||
"mc-client-updater-server/pkg/log"
|
||||
"time"
|
||||
)
|
||||
|
||||
func NewToken(aud string) string {
|
||||
auds := make([]string, 1)
|
||||
auds = append(auds, aud)
|
||||
now := time.Now()
|
||||
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims{
|
||||
"aud": auds,
|
||||
"iat": now,
|
||||
"nbf": now,
|
||||
})
|
||||
tokenStr, err := token.SignedString([]byte(conf.Conf.Security.JWTSecret))
|
||||
if err != nil {
|
||||
log.Logger.Error("生成Token失败:", err)
|
||||
return ""
|
||||
}
|
||||
return tokenStr
|
||||
}
|
||||
Reference in New Issue
Block a user