李伟乐 2 years ago
parent 8b2e767347
commit ee2175422c
  1. 4
      middleware/jwt/jwt.go
  2. 3
      middleware/jwt/token.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
}

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

Loading…
Cancel
Save