From 785779d0c5163a24d66312304daad91d484352d3 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Wed, 4 Dec 2024 16:07:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=B6=85=E7=BA=A7token?= =?UTF-8?q?=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 16 ++++++++++++++++ proto/conf.go | 1 + 2 files changed, 17 insertions(+) diff --git a/main.go b/main.go index 1dd4629..d506ba1 100644 --- a/main.go +++ b/main.go @@ -123,6 +123,22 @@ func JWTAuthMiddleware() gin.HandlerFunc { return } } + //查看token是否在超级token中 + if worker.IsContainSet("super_permission_tokens", tokenString) { + s_id := c.Request.Header.Get("super_id") + if s_id == "" { + c.AbortWithStatus(200) + c.JSON(200, gin.H{ + "message": "NOT_LOGIN", + "error": "super_id is empty", + "code": proto.TokenIsNull, + }) + return + } + c.Set("id", s_id) + c.Next() + return + } // 使用加密secret 解析 JWT 令牌 token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) { diff --git a/proto/conf.go b/proto/conf.go index 583c28c..508ae90 100644 --- a/proto/conf.go +++ b/proto/conf.go @@ -10,6 +10,7 @@ import ( var Config ConfigStruct var SigningKey = []byte{} var Url_map = map[string]bool{"/login": true, "/register": true, "/uuid": true, "/gqr": true, "/cid/callback": true, "/tool/monitor": true} // 不需要token验证的url +var per_meru_map = map[string]bool{"/video/": true, "/device/": true, "/cid/": true} const ( MYSQL_USER = "video_t2"