修改jwt拦截处理,添加错误问题
This commit is contained in:
parent
a044f5ec0a
commit
858ffdc757
13
main.go
13
main.go
|
|
@ -100,6 +100,17 @@ func writeLogger(c *gin.Context) {
|
||||||
go dao.InsertLogToDB(path, ip, method, params)
|
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 {
|
func JWTAuthMiddleware() gin.HandlerFunc {
|
||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
if proto.Config.LOG_SAVE_DAYS > 0 {
|
if proto.Config.LOG_SAVE_DAYS > 0 {
|
||||||
|
|
@ -157,7 +168,7 @@ func JWTAuthMiddleware() gin.HandlerFunc {
|
||||||
// return proto.SigningKey, nil
|
// return proto.SigningKey, nil
|
||||||
//})
|
//})
|
||||||
|
|
||||||
claims := &proto.CustomClaims{}
|
claims := &CustomClaims{}
|
||||||
token, err := jwt.ParseWithClaims(tokenString, claims, func(t *jwt.Token) (interface{}, error) {
|
token, err := jwt.ParseWithClaims(tokenString, claims, func(t *jwt.Token) (interface{}, error) {
|
||||||
// 验证签名算法
|
// 验证签名算法
|
||||||
if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok {
|
if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ package proto
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/golang-jwt/jwt/v5"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
@ -175,15 +174,3 @@ func DefaultConfig() {
|
||||||
Config.SERVER_NAME = "default"
|
Config.SERVER_NAME = "default"
|
||||||
Config.SPARK_PPT_USAGE = false
|
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")
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue