From 858ffdc757cc33f6046cf18aaa278245367f9e36 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Sun, 18 May 2025 14:15:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9jwt=E6=8B=A6=E6=88=AA?= =?UTF-8?q?=E5=A4=84=E7=90=86=EF=BC=8C=E6=B7=BB=E5=8A=A0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 13 ++++++++++++- proto/conf.go | 13 ------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/main.go b/main.go index 5ae6252..2902f29 100644 --- a/main.go +++ b/main.go @@ -100,6 +100,17 @@ func writeLogger(c *gin.Context) { go dao.InsertLogToDB(path, ip, method, params) } +type CustomClaims struct { + ID string `json:"id"` + Username string `json:"username"` + UserID int `json:"user_id"` +} + +func (c CustomClaims) Valid() error { + //TODO implement me + panic("custom claims valid not implement yet!") +} + func JWTAuthMiddleware() gin.HandlerFunc { return func(c *gin.Context) { if proto.Config.LOG_SAVE_DAYS > 0 { @@ -157,7 +168,7 @@ func JWTAuthMiddleware() gin.HandlerFunc { // return proto.SigningKey, nil //}) - claims := &proto.CustomClaims{} + claims := &CustomClaims{} token, err := jwt.ParseWithClaims(tokenString, claims, func(t *jwt.Token) (interface{}, error) { // 验证签名算法 if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok { diff --git a/proto/conf.go b/proto/conf.go index 58a43b8..cbc7196 100644 --- a/proto/conf.go +++ b/proto/conf.go @@ -3,7 +3,6 @@ package proto import ( "encoding/json" "fmt" - "github.com/golang-jwt/jwt/v5" "gorm.io/gorm" "log" "os" @@ -175,15 +174,3 @@ func DefaultConfig() { Config.SERVER_NAME = "default" Config.SPARK_PPT_USAGE = false } - -type CustomClaims struct { - ID string `json:"id"` - Username string `json:"username"` - UserID int `json:"user_id"` - jwt.RegisteredClaims -} - -func (c CustomClaims) Valid() error { - //TODO implement me - panic("implement me") -}