Skip to content

Commit

Permalink
修复jwt安全问题,新增server.jwtKey配置,不配置则使用server.projectName
Browse files Browse the repository at this point in the history
  • Loading branch information
demozx committed Aug 19, 2024
1 parent 6e62bf9 commit be702ad
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions internal/logic/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package auth
import (
"context"
"gf_cms/internal/logic/admin"
"gf_cms/internal/logic/util"
"gf_cms/internal/model"
"gf_cms/internal/service"
"time"
Expand Down Expand Up @@ -33,8 +34,8 @@ func init() {
service.RegisterAuth(New())

auth := jwt.New(&jwt.GfJWTMiddleware{
Realm: "test zone",
Key: []byte("secret key"),
Realm: util.Util().ProjectName() + "_backend",
Key: []byte(util.Util().JwtKey()),
Timeout: time.Minute * 5,
MaxRefresh: time.Minute * 5,
IdentityKey: "id",
Expand Down
9 changes: 9 additions & 0 deletions internal/logic/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ func (*sUtil) ProjectName() string {
return ProjectName.String()
}

// JwtKey 获取JwtKey
func (*sUtil) JwtKey() string {
jwtKey := Util().GetConfig("server.jwtKey")
if jwtKey == "" {
return ProjectName.String()
}
return jwtKey
}

// SystemRoot 获取SystemRoot
func (*sUtil) SystemRoot() string {
return SystemRoot
Expand Down
2 changes: 2 additions & 0 deletions internal/service/util.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions manifest/config/config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ server:
projectName: "gf_cms"
backendPrefix: "admin"
address: ":8001"
jwtKey: "" # jwt密钥不配置将使用projectName为了安全一定要配置
openapiPath: "/api.json"
# swaggerPath: "/swagger" #使用自定义SwaggerUI,需注释该行
serverRoot: "resource/public"
Expand Down

0 comments on commit be702ad

Please sign in to comment.