From fb4414fab68ba7226bb1c75b63d67af16e13a33b Mon Sep 17 00:00:00 2001 From: eson <9673575+githubcontent@user.noreply.gitee.com> Date: Mon, 10 Jul 2023 17:54:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AC=E6=88=90=20=E6=A0=87=E5=87=86?= =?UTF-8?q?=E7=9A=84jwt=20Token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- goctl_template/api/context.tpl | 2 ++ server/backend/internal/svc/servicecontext.go | 2 ++ server/canteen/internal/svc/servicecontext.go | 2 ++ server/data-transfer/internal/svc/servicecontext.go | 2 ++ server/home-user-auth/internal/svc/servicecontext.go | 1 + server/inventory/internal/svc/servicecontext.go | 1 + server/map-library/internal/svc/servicecontext.go | 2 ++ server/orders/internal/svc/servicecontext.go | 2 ++ server/product-model/internal/svc/servicecontext.go | 1 + server/product-template/internal/svc/servicecontext.go | 2 ++ server/product/internal/svc/servicecontext.go | 2 ++ .../shopping-cart-confirmation/internal/svc/servicecontext.go | 2 ++ server/upload/internal/svc/servicecontext.go | 1 + server/webset/internal/svc/servicecontext.go | 1 + 14 files changed, 23 insertions(+) diff --git a/goctl_template/api/context.tpl b/goctl_template/api/context.tpl index 8a837607..3195fe63 100644 --- a/goctl_template/api/context.tpl +++ b/goctl_template/api/context.tpl @@ -36,6 +36,8 @@ func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err if AuthKey == "" { return nil, nil } + AuthKey = AuthKey[7:] + if len(AuthKey) <= 50 { return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) diff --git a/server/backend/internal/svc/servicecontext.go b/server/backend/internal/svc/servicecontext.go index 35489171..65b6d2e3 100644 --- a/server/backend/internal/svc/servicecontext.go +++ b/server/backend/internal/svc/servicecontext.go @@ -37,6 +37,8 @@ func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) } + AuthKey = AuthKey[7:] + token, err := jwt.Parse(AuthKey, func(token *jwt.Token) (interface{}, error) { // 检查签名方法是否为 HS256 if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { diff --git a/server/canteen/internal/svc/servicecontext.go b/server/canteen/internal/svc/servicecontext.go index 9712cabb..2788d4c5 100644 --- a/server/canteen/internal/svc/servicecontext.go +++ b/server/canteen/internal/svc/servicecontext.go @@ -34,6 +34,8 @@ func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err if AuthKey == "" { return nil, nil } + AuthKey = AuthKey[7:] + if len(AuthKey) <= 50 { return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) } diff --git a/server/data-transfer/internal/svc/servicecontext.go b/server/data-transfer/internal/svc/servicecontext.go index 3236a65d..977aec29 100644 --- a/server/data-transfer/internal/svc/servicecontext.go +++ b/server/data-transfer/internal/svc/servicecontext.go @@ -34,6 +34,8 @@ func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err if AuthKey == "" { return nil, nil } + AuthKey = AuthKey[7:] + if len(AuthKey) <= 50 { return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) } diff --git a/server/home-user-auth/internal/svc/servicecontext.go b/server/home-user-auth/internal/svc/servicecontext.go index bcd09a0b..a4caca94 100644 --- a/server/home-user-auth/internal/svc/servicecontext.go +++ b/server/home-user-auth/internal/svc/servicecontext.go @@ -34,6 +34,7 @@ func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err if AuthKey == "" { return nil, nil } + AuthKey = AuthKey[7:] if len(AuthKey) <= 50 { return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) diff --git a/server/inventory/internal/svc/servicecontext.go b/server/inventory/internal/svc/servicecontext.go index f30de860..0212ac41 100644 --- a/server/inventory/internal/svc/servicecontext.go +++ b/server/inventory/internal/svc/servicecontext.go @@ -34,6 +34,7 @@ func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err if AuthKey == "" { return nil, nil } + AuthKey = AuthKey[7:] if len(AuthKey) <= 50 { return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) diff --git a/server/map-library/internal/svc/servicecontext.go b/server/map-library/internal/svc/servicecontext.go index 5ee6e83a..4dd33ccd 100644 --- a/server/map-library/internal/svc/servicecontext.go +++ b/server/map-library/internal/svc/servicecontext.go @@ -34,6 +34,8 @@ func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err if AuthKey == "" { return nil, nil } + AuthKey = AuthKey[7:] + if len(AuthKey) <= 50 { return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) } diff --git a/server/orders/internal/svc/servicecontext.go b/server/orders/internal/svc/servicecontext.go index 61d8b459..53a50bcd 100644 --- a/server/orders/internal/svc/servicecontext.go +++ b/server/orders/internal/svc/servicecontext.go @@ -34,6 +34,8 @@ func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err if AuthKey == "" { return nil, nil } + AuthKey = AuthKey[7:] + if len(AuthKey) <= 50 { return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) } diff --git a/server/product-model/internal/svc/servicecontext.go b/server/product-model/internal/svc/servicecontext.go index 4fe39c6a..aeb87e43 100644 --- a/server/product-model/internal/svc/servicecontext.go +++ b/server/product-model/internal/svc/servicecontext.go @@ -34,6 +34,7 @@ func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err if AuthKey == "" { return nil, nil } + AuthKey = AuthKey[7:] if len(AuthKey) <= 50 { return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) diff --git a/server/product-template/internal/svc/servicecontext.go b/server/product-template/internal/svc/servicecontext.go index b2001218..fe6a4c65 100644 --- a/server/product-template/internal/svc/servicecontext.go +++ b/server/product-template/internal/svc/servicecontext.go @@ -34,6 +34,8 @@ func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err if AuthKey == "" { return nil, nil } + AuthKey = AuthKey[7:] + if len(AuthKey) <= 50 { return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) } diff --git a/server/product/internal/svc/servicecontext.go b/server/product/internal/svc/servicecontext.go index 941adabc..fbf87bb8 100644 --- a/server/product/internal/svc/servicecontext.go +++ b/server/product/internal/svc/servicecontext.go @@ -34,6 +34,8 @@ func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err if AuthKey == "" { return nil, nil } + AuthKey = AuthKey[7:] + if len(AuthKey) <= 50 { return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) } diff --git a/server/shopping-cart-confirmation/internal/svc/servicecontext.go b/server/shopping-cart-confirmation/internal/svc/servicecontext.go index 25e27c80..50fcc085 100644 --- a/server/shopping-cart-confirmation/internal/svc/servicecontext.go +++ b/server/shopping-cart-confirmation/internal/svc/servicecontext.go @@ -34,6 +34,8 @@ func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err if AuthKey == "" { return nil, nil } + AuthKey = AuthKey[7:] + if len(AuthKey) <= 50 { return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) } diff --git a/server/upload/internal/svc/servicecontext.go b/server/upload/internal/svc/servicecontext.go index dacb4db0..bd77c125 100644 --- a/server/upload/internal/svc/servicecontext.go +++ b/server/upload/internal/svc/servicecontext.go @@ -45,6 +45,7 @@ func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err if AuthKey == "" { return nil, nil } + AuthKey = AuthKey[7:] if len(AuthKey) <= 50 { return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey))) diff --git a/server/webset/internal/svc/servicecontext.go b/server/webset/internal/svc/servicecontext.go index dac5a5fd..b5a9960f 100644 --- a/server/webset/internal/svc/servicecontext.go +++ b/server/webset/internal/svc/servicecontext.go @@ -34,6 +34,7 @@ func (svcCtx *ServiceContext) ParseJwtToken(r *http.Request) (jwt.MapClaims, err if AuthKey == "" { return nil, nil } + AuthKey = AuthKey[7:] if len(AuthKey) <= 50 { return nil, errors.New(fmt.Sprint("Error parsing token, len:", len(AuthKey)))