修改jwt拦截处理,添加错误问题

This commit is contained in:
junleea 2025-05-18 14:15:46 +08:00
parent a044f5ec0a
commit 858ffdc757
2 changed files with 12 additions and 14 deletions

13
main.go
View File

@ -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 {

View File

@ -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")
}