From ee2175422c3194baea86a6dd58e94ab5c70c9a0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E4=BC=9F=E4=B9=90?= Date: Thu, 16 Mar 2023 11:05:32 +0800 Subject: [PATCH] x --- middleware/jwt/jwt.go | 4 ++-- middleware/jwt/token.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/middleware/jwt/jwt.go b/middleware/jwt/jwt.go index 0625394..f9ab0a0 100644 --- a/middleware/jwt/jwt.go +++ b/middleware/jwt/jwt.go @@ -15,7 +15,7 @@ type userIdKey struct{} type authKey struct { } -type ParseFunc func(key string, tokenStr string) (*UserInfo, error) +type ParseFunc func(ctx context.Context, key string, tokenStr string) (*UserInfo, error) type JwtOption func(o *options) func WithJwtKey(jwtKey string) JwtOption { @@ -71,7 +71,7 @@ func JWT(opts ...JwtOption) middleware.Middleware { if tr, ok := transport.FromServerContext(ctx); ok { tokenStr = tr.RequestHeader().Get("token") } - userInfo, err := cfg.parseFunc(cfg.jwtKey, tokenStr) + userInfo, err := cfg.parseFunc(ctx, cfg.jwtKey, tokenStr) if err != nil { return nil, err } diff --git a/middleware/jwt/token.go b/middleware/jwt/token.go index 2597a1b..8220cb3 100644 --- a/middleware/jwt/token.go +++ b/middleware/jwt/token.go @@ -1,6 +1,7 @@ package jwt import ( + "context" "encoding/json" "git.diulo.com/mogfee/kit/errors" "git.diulo.com/mogfee/kit/internal/xuuid" @@ -53,7 +54,7 @@ func GetToken(key string, info *UserInfo) (token string, uniqId string, err erro return } -func Parse(key string, tokenStr string) (*UserInfo, error) { +func Parse(ctx context.Context, key string, tokenStr string) (*UserInfo, error) { if tokenStr == "" { return nil, errors.Unauthorized("TOKEN_ERROR", "") }