|
|
|
@ -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 |
|
|
|
|
} |
|
|
|
|