mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-09 23:17:21 +08:00
fix: jwt signing key 使用随机字符串存入数据库
This commit is contained in:
parent
3f3d24648b
commit
702b881ca1
3 changed files with 9 additions and 2 deletions
|
@ -6,7 +6,6 @@ const (
|
||||||
|
|
||||||
AuthMethodJWT = "jwt"
|
AuthMethodJWT = "jwt"
|
||||||
JWTHeaderName = "Authorization"
|
JWTHeaderName = "Authorization"
|
||||||
JWTSigningKey = "1panelKey"
|
|
||||||
JWTBufferTime = 86400
|
JWTBufferTime = 86400
|
||||||
JWTIssuer = "1Panel"
|
JWTIssuer = "1Panel"
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/model"
|
"github.com/1Panel-dev/1Panel/backend/app/model"
|
||||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||||
"github.com/1Panel-dev/1Panel/backend/global"
|
"github.com/1Panel-dev/1Panel/backend/global"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/utils/common"
|
||||||
|
|
||||||
"github.com/go-gormigrate/gormigrate/v2"
|
"github.com/go-gormigrate/gormigrate/v2"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
@ -93,6 +94,10 @@ var AddTableSetting = &gormigrate.Migration{
|
||||||
if err := tx.Create(&model.Setting{Key: "SecurityEntrance", Value: "onepanel"}).Error; err != nil {
|
if err := tx.Create(&model.Setting{Key: "SecurityEntrance", Value: "onepanel"}).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err := tx.Create(&model.Setting{Key: "JWTSigningKey", Value: common.RandStr(16)}).Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if err := tx.Create(&model.Setting{Key: "ExpirationTime", Value: time.Now().AddDate(0, 0, 10).Format("2006-01-02 15:04:05")}).Error; err != nil {
|
if err := tx.Create(&model.Setting{Key: "ExpirationTime", Value: time.Now().AddDate(0, 0, 10).Format("2006-01-02 15:04:05")}).Error; err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package jwt
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/app/repo"
|
||||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||||
|
|
||||||
"github.com/golang-jwt/jwt/v4"
|
"github.com/golang-jwt/jwt/v4"
|
||||||
|
@ -30,8 +31,10 @@ type BaseClaims struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewJWT() *JWT {
|
func NewJWT() *JWT {
|
||||||
|
settingRepo := repo.NewISettingRepo()
|
||||||
|
jwtSign, _ := settingRepo.Get(settingRepo.WithByKey("JWTSigningKey"))
|
||||||
return &JWT{
|
return &JWT{
|
||||||
[]byte(constant.JWTSigningKey),
|
[]byte(jwtSign.Value),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue