登录功能完成

This commit is contained in:
2022-10-04 00:36:01 +08:00
parent 26278707bb
commit 968eab9b06
31 changed files with 1022 additions and 36 deletions

25
pkg/token/jwt.go Normal file
View 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
}