diff --git a/cmd/thv-operator/api/v1beta1/mcpexternalauthconfig_types.go b/cmd/thv-operator/api/v1beta1/mcpexternalauthconfig_types.go index 29d677190e..d4da70ed1d 100644 --- a/cmd/thv-operator/api/v1beta1/mcpexternalauthconfig_types.go +++ b/cmd/thv-operator/api/v1beta1/mcpexternalauthconfig_types.go @@ -278,7 +278,7 @@ type OBOConfig struct { // TokenExchangeConfig holds configuration for RFC-8693 OAuth 2.0 Token Exchange. // This configuration is used to exchange incoming authentication tokens for tokens // that can be used with external services. -// The structure matches the tokenexchange.Config from pkg/oauthproto/tokenexchange/middleware.go +// The structure matches the tokenexchange.Config from pkg/auth/tokenexchange/middleware.go type TokenExchangeConfig struct { // TokenURL is the OAuth 2.0 token endpoint URL for token exchange // +kubebuilder:validation:Required diff --git a/cmd/thv-operator/pkg/controllerutil/tokenexchange.go b/cmd/thv-operator/pkg/controllerutil/tokenexchange.go index e568ee068d..15228b6a13 100644 --- a/cmd/thv-operator/pkg/controllerutil/tokenexchange.go +++ b/cmd/thv-operator/pkg/controllerutil/tokenexchange.go @@ -18,7 +18,8 @@ import ( "github.com/stacklok/toolhive/pkg/auth/awssts" "github.com/stacklok/toolhive/pkg/auth/obo" "github.com/stacklok/toolhive/pkg/auth/remote" - "github.com/stacklok/toolhive/pkg/oauthproto/tokenexchange" + "github.com/stacklok/toolhive/pkg/auth/tokenexchange" + exchange "github.com/stacklok/toolhive/pkg/oauthproto/tokenexchange" "github.com/stacklok/toolhive/pkg/runner" ) @@ -358,7 +359,7 @@ func addTokenExchangeConfig( } // Normalize SubjectTokenType to full URN (accepts both short forms and full URNs) - normalizedTokenType, err := tokenexchange.NormalizeTokenType(tokenExchangeSpec.SubjectTokenType) + normalizedTokenType, err := exchange.NormalizeTokenType(tokenExchangeSpec.SubjectTokenType) if err != nil { return fmt.Errorf("invalid subject token type: %w", err) } diff --git a/cmd/thv/app/auth_flags.go b/cmd/thv/app/auth_flags.go index fed12e75d3..6681d60464 100644 --- a/cmd/thv/app/auth_flags.go +++ b/cmd/thv/app/auth_flags.go @@ -13,7 +13,8 @@ import ( "github.com/spf13/cobra" - "github.com/stacklok/toolhive/pkg/oauthproto/tokenexchange" + "github.com/stacklok/toolhive/pkg/auth/tokenexchange" + exchange "github.com/stacklok/toolhive/pkg/oauthproto/tokenexchange" "github.com/stacklok/toolhive/pkg/runner" ) @@ -129,7 +130,7 @@ func (f *RemoteAuthFlags) BuildTokenExchangeConfig() (*tokenexchange.Config, err normalizedTokenType := f.TokenExchangeSubjectTokenType if normalizedTokenType != "" { var err error - normalizedTokenType, err = tokenexchange.NormalizeTokenType(normalizedTokenType) + normalizedTokenType, err = exchange.NormalizeTokenType(normalizedTokenType) if err != nil { return nil, fmt.Errorf("invalid subject token type: %w", err) } diff --git a/cmd/thv/app/proxy.go b/cmd/thv/app/proxy.go index b233ea5962..0f96312871 100644 --- a/cmd/thv/app/proxy.go +++ b/cmd/thv/app/proxy.go @@ -20,9 +20,9 @@ import ( "github.com/stacklok/toolhive/pkg/auth/discovery" "github.com/stacklok/toolhive/pkg/auth/oauth" "github.com/stacklok/toolhive/pkg/auth/remote" + "github.com/stacklok/toolhive/pkg/auth/tokenexchange" "github.com/stacklok/toolhive/pkg/bodylimit" "github.com/stacklok/toolhive/pkg/networking" - "github.com/stacklok/toolhive/pkg/oauthproto/tokenexchange" "github.com/stacklok/toolhive/pkg/transport" "github.com/stacklok/toolhive/pkg/transport/middleware" "github.com/stacklok/toolhive/pkg/transport/middleware/origin" diff --git a/docs/arch/03-transport-architecture.md b/docs/arch/03-transport-architecture.md index f8d2e8690c..ae694c25f6 100644 --- a/docs/arch/03-transport-architecture.md +++ b/docs/arch/03-transport-architecture.md @@ -263,6 +263,15 @@ Ownership* in [Virtual MCP](10-virtual-mcp-architecture.md). ### Middleware Integration +Token exchange's host adapter and host tests live in `pkg/auth/tokenexchange`; +`factory.go` handles runner setup and lifecycle, while `middleware.go` holds +runtime behavior and configuration. Reusable RFC 8693 exchange and normalization +remain in `pkg/oauthproto/tokenexchange`. +The host depends on the reusable package, never the reverse. Runner startup uses +`GetSupportedMiddlewareFactories` to select the host factory by `tokenexchange`; +there is no token-exchange `init()` registration. See the +[Go API migration](../middleware.md#8-token-exchange-middleware) for moved symbols. + All proxy types integrate with the middleware chain: ```mermaid diff --git a/docs/middleware.md b/docs/middleware.md index 7ed7bf864b..c9a38deb4e 100644 --- a/docs/middleware.md +++ b/docs/middleware.md @@ -440,7 +440,29 @@ thv config usage-metrics enable **Purpose**: Exchanges incoming JWT tokens for external service tokens using OAuth 2.0 Token Exchange (RFC 8693). -**Location**: `pkg/oauthproto/tokenexchange/middleware.go` +**Location**: `pkg/auth/tokenexchange/middleware.go` (runtime and configuration) +and `pkg/auth/tokenexchange/factory.go` (runner factory and lifecycle). + +**Go API migration (OWN-05)**: Host middleware moved from +`github.com/stacklok/toolhive/pkg/oauthproto/tokenexchange` to +`github.com/stacklok/toolhive/pkg/auth/tokenexchange`. Update imports for these symbols: + +- `Config`, `MiddlewareParams`, `Middleware` (including `Handler` and `Close`) +- `MiddlewareType`, `HeaderStrategyReplace`, `HeaderStrategyCustom`, `EnvClientSecret` +- `SubjectTokenProvider` +- `CreateMiddleware`, `CreateMiddlewareFromHeader`, `CreateMiddlewareFromTokenSource` + +`ExchangeConfig` (including `Validate` and `TokenSource`) and `NormalizeTokenType` +remain in `pkg/oauthproto/tokenexchange`. Code using both layers should import +that package with an alias such as `exchange`, and the host package as +`tokenexchange`. There is no compatibility wrapper from the reusable package +back to the host. This is an import/ownership migration, not a runtime feature +change: configuration keys, defaults, environment variables, authentication, +headers, errors, and token-source lifetime remain unchanged. + +The runner explicitly maps `tokenexchange.MiddlewareType` to the host +`CreateMiddleware` in `GetSupportedMiddlewareFactories`; neither package relies +on `init()` registration. Direct proxy callers use the two host constructors. **Responsibilities**: - Extract claims from authenticated JWT tokens diff --git a/docs/operator/crd-api.md b/docs/operator/crd-api.md index ed188654e5..f80621a716 100644 --- a/docs/operator/crd-api.md +++ b/docs/operator/crd-api.md @@ -4567,7 +4567,7 @@ _Appears in:_ TokenExchangeConfig holds configuration for RFC-8693 OAuth 2.0 Token Exchange. This configuration is used to exchange incoming authentication tokens for tokens that can be used with external services. -The structure matches the tokenexchange.Config from pkg/oauthproto/tokenexchange/middleware.go +The structure matches the tokenexchange.Config from pkg/auth/tokenexchange/middleware.go diff --git a/pkg/auth/obo/middleware.go b/pkg/auth/obo/middleware.go index ce527355bc..60ea79da98 100644 --- a/pkg/auth/obo/middleware.go +++ b/pkg/auth/obo/middleware.go @@ -75,7 +75,7 @@ func DefaultFactory(config *types.MiddlewareConfig, runner types.MiddlewareRunne // produces a 503 stub. // // Declared as a function (matching sibling middleware packages such as -// awssts, upstreamswap, and oauthproto/tokenexchange) so RegisterFactory is +// awssts, upstreamswap, and tokenexchange) so RegisterFactory is // the only mutation path — there is no second escape hatch via direct // assignment to CreateMiddleware. func CreateMiddleware(config *types.MiddlewareConfig, runner types.MiddlewareRunner) error { diff --git a/pkg/auth/tokenexchange/factory.go b/pkg/auth/tokenexchange/factory.go new file mode 100644 index 0000000000..8569f72d94 --- /dev/null +++ b/pkg/auth/tokenexchange/factory.go @@ -0,0 +1,75 @@ +// SPDX-FileCopyrightText: Copyright 2025 Stacklok, Inc. +// SPDX-License-Identifier: Apache-2.0 + +package tokenexchange + +import ( + "encoding/json" + "fmt" + + "github.com/stacklok/toolhive/pkg/transport/types" +) + +// Middleware wraps token exchange middleware functionality +type Middleware struct { + middleware types.MiddlewareFunction +} + +// Handler returns the middleware function used by the proxy. +func (m *Middleware) Handler() types.MiddlewareFunction { + return m.middleware +} + +// Close cleans up any resources used by the middleware. +func (*Middleware) Close() error { + // Token exchange middleware doesn't need cleanup + return nil +} + +// CreateMiddleware factory function for token exchange middleware +func CreateMiddleware(config *types.MiddlewareConfig, runner types.MiddlewareRunner) error { + var params MiddlewareParams + if err := json.Unmarshal(config.Parameters, ¶ms); err != nil { + return fmt.Errorf("failed to unmarshal token exchange middleware parameters: %w", err) + } + + // Token exchange config is required when this middleware type is specified + if params.TokenExchangeConfig == nil { + return fmt.Errorf("token exchange configuration is required but not provided") + } + + // Validate configuration + if err := validateTokenExchangeConfig(params.TokenExchangeConfig); err != nil { + return fmt.Errorf("invalid token exchange configuration: %w", err) + } + + middleware, err := createTokenExchangeMiddleware(*params.TokenExchangeConfig, nil, defaultEnvGetter) + if err != nil { + return fmt.Errorf("invalid token exchange middleware config: %w", err) + } + + tokenExchangeMw := &Middleware{ + middleware: middleware, + } + + // Add middleware to runner + runner.AddMiddleware(config.Type, tokenExchangeMw) + + return nil +} + +// validateTokenExchangeConfig validates the token exchange configuration +func validateTokenExchangeConfig(config *Config) error { + if config.HeaderStrategy == HeaderStrategyCustom && config.ExternalTokenHeaderName == "" { + return fmt.Errorf("external_token_header_name must be specified when header_strategy is '%s'", HeaderStrategyCustom) + } + + if config.HeaderStrategy != "" && + config.HeaderStrategy != HeaderStrategyReplace && + config.HeaderStrategy != HeaderStrategyCustom { + return fmt.Errorf("invalid header_strategy: %s (valid values: '%s', '%s')", + config.HeaderStrategy, HeaderStrategyReplace, HeaderStrategyCustom) + } + + return nil +} diff --git a/pkg/oauthproto/tokenexchange/middleware.go b/pkg/auth/tokenexchange/middleware.go similarity index 83% rename from pkg/oauthproto/tokenexchange/middleware.go rename to pkg/auth/tokenexchange/middleware.go index 9b2b07640e..3d22ec86bf 100644 --- a/pkg/oauthproto/tokenexchange/middleware.go +++ b/pkg/auth/tokenexchange/middleware.go @@ -1,10 +1,10 @@ // SPDX-FileCopyrightText: Copyright 2025 Stacklok, Inc. // SPDX-License-Identifier: Apache-2.0 +// Package tokenexchange adapts reusable OAuth token exchange to ToolHive middleware. package tokenexchange import ( - "encoding/json" "errors" "fmt" "log/slog" @@ -16,6 +16,7 @@ import ( "github.com/stacklok/toolhive/pkg/auth" "github.com/stacklok/toolhive/pkg/oauthproto" + exchange "github.com/stacklok/toolhive/pkg/oauthproto/tokenexchange" "github.com/stacklok/toolhive/pkg/transport/types" ) @@ -84,70 +85,6 @@ type Config struct { ExternalTokenHeaderName string `json:"external_token_header_name,omitempty"` } -// Middleware wraps token exchange middleware functionality -type Middleware struct { - middleware types.MiddlewareFunction -} - -// Handler returns the middleware function used by the proxy. -func (m *Middleware) Handler() types.MiddlewareFunction { - return m.middleware -} - -// Close cleans up any resources used by the middleware. -func (*Middleware) Close() error { - // Token exchange middleware doesn't need cleanup - return nil -} - -// CreateMiddleware factory function for token exchange middleware -func CreateMiddleware(config *types.MiddlewareConfig, runner types.MiddlewareRunner) error { - var params MiddlewareParams - if err := json.Unmarshal(config.Parameters, ¶ms); err != nil { - return fmt.Errorf("failed to unmarshal token exchange middleware parameters: %w", err) - } - - // Token exchange config is required when this middleware type is specified - if params.TokenExchangeConfig == nil { - return fmt.Errorf("token exchange configuration is required but not provided") - } - - // Validate configuration - if err := validateTokenExchangeConfig(params.TokenExchangeConfig); err != nil { - return fmt.Errorf("invalid token exchange configuration: %w", err) - } - - middleware, err := createTokenExchangeMiddleware(*params.TokenExchangeConfig, nil, defaultEnvGetter) - if err != nil { - return fmt.Errorf("invalid token exchange middleware config: %w", err) - } - - tokenExchangeMw := &Middleware{ - middleware: middleware, - } - - // Add middleware to runner - runner.AddMiddleware(config.Type, tokenExchangeMw) - - return nil -} - -// validateTokenExchangeConfig validates the token exchange configuration -func validateTokenExchangeConfig(config *Config) error { - if config.HeaderStrategy == HeaderStrategyCustom && config.ExternalTokenHeaderName == "" { - return fmt.Errorf("external_token_header_name must be specified when header_strategy is '%s'", HeaderStrategyCustom) - } - - if config.HeaderStrategy != "" && - config.HeaderStrategy != HeaderStrategyReplace && - config.HeaderStrategy != HeaderStrategyCustom { - return fmt.Errorf("invalid header_strategy: %s (valid values: '%s', '%s')", - config.HeaderStrategy, HeaderStrategyReplace, HeaderStrategyCustom) - } - - return nil -} - // injectionFunc is a function that injects a token into an HTTP request type injectionFunc func(*http.Request, string) error @@ -287,7 +224,7 @@ func createTokenExchangeMiddleware( } // Create base exchange config at startup time with all static fields - baseExchangeConfig := ExchangeConfig{ + baseExchangeConfig := exchange.ExchangeConfig{ TokenURL: config.TokenURL, ClientID: config.ClientID, ClientSecret: clientSecret, diff --git a/pkg/oauthproto/tokenexchange/middleware_test.go b/pkg/auth/tokenexchange/middleware_test.go similarity index 100% rename from pkg/oauthproto/tokenexchange/middleware_test.go rename to pkg/auth/tokenexchange/middleware_test.go diff --git a/pkg/runner/config.go b/pkg/runner/config.go index c6d86ae40f..62a9ae0e77 100644 --- a/pkg/runner/config.go +++ b/pkg/runner/config.go @@ -18,6 +18,7 @@ import ( "github.com/stacklok/toolhive/pkg/auth/awssts" "github.com/stacklok/toolhive/pkg/auth/remote" authsecrets "github.com/stacklok/toolhive/pkg/auth/secrets" + "github.com/stacklok/toolhive/pkg/auth/tokenexchange" "github.com/stacklok/toolhive/pkg/auth/upstreamswap" "github.com/stacklok/toolhive/pkg/authserver" "github.com/stacklok/toolhive/pkg/authz" @@ -28,7 +29,6 @@ import ( "github.com/stacklok/toolhive/pkg/ignore" "github.com/stacklok/toolhive/pkg/labels" "github.com/stacklok/toolhive/pkg/networking" - "github.com/stacklok/toolhive/pkg/oauthproto/tokenexchange" "github.com/stacklok/toolhive/pkg/redisconfig" "github.com/stacklok/toolhive/pkg/secrets" "github.com/stacklok/toolhive/pkg/state" diff --git a/pkg/runner/config_builder.go b/pkg/runner/config_builder.go index 83224521bd..8968482f50 100644 --- a/pkg/runner/config_builder.go +++ b/pkg/runner/config_builder.go @@ -23,6 +23,7 @@ import ( "github.com/stacklok/toolhive/pkg/auth" "github.com/stacklok/toolhive/pkg/auth/awssts" "github.com/stacklok/toolhive/pkg/auth/remote" + "github.com/stacklok/toolhive/pkg/auth/tokenexchange" "github.com/stacklok/toolhive/pkg/authserver" "github.com/stacklok/toolhive/pkg/authserver/server/registration" "github.com/stacklok/toolhive/pkg/authz" @@ -33,7 +34,6 @@ import ( "github.com/stacklok/toolhive/pkg/labels" "github.com/stacklok/toolhive/pkg/mcp" "github.com/stacklok/toolhive/pkg/networking" - "github.com/stacklok/toolhive/pkg/oauthproto/tokenexchange" "github.com/stacklok/toolhive/pkg/recovery" "github.com/stacklok/toolhive/pkg/telemetry" "github.com/stacklok/toolhive/pkg/transport" diff --git a/pkg/runner/config_builder_test.go b/pkg/runner/config_builder_test.go index 7914773ea3..2aa19d8fa3 100644 --- a/pkg/runner/config_builder_test.go +++ b/pkg/runner/config_builder_test.go @@ -18,13 +18,13 @@ import ( regtypes "github.com/stacklok/toolhive-core/registry/types" "github.com/stacklok/toolhive/pkg/audit" "github.com/stacklok/toolhive/pkg/auth" + "github.com/stacklok/toolhive/pkg/auth/tokenexchange" "github.com/stacklok/toolhive/pkg/authserver" "github.com/stacklok/toolhive/pkg/authserver/server/registration" "github.com/stacklok/toolhive/pkg/authz" appconfig "github.com/stacklok/toolhive/pkg/config" "github.com/stacklok/toolhive/pkg/mcp" "github.com/stacklok/toolhive/pkg/networking" - "github.com/stacklok/toolhive/pkg/oauthproto/tokenexchange" "github.com/stacklok/toolhive/pkg/transport/types" "github.com/stacklok/toolhive/pkg/webhook" ) diff --git a/pkg/runner/middleware.go b/pkg/runner/middleware.go index 7e52885f82..90cbf790c1 100644 --- a/pkg/runner/middleware.go +++ b/pkg/runner/middleware.go @@ -15,6 +15,7 @@ import ( "github.com/stacklok/toolhive/pkg/auth" "github.com/stacklok/toolhive/pkg/auth/awssts" "github.com/stacklok/toolhive/pkg/auth/obo" + "github.com/stacklok/toolhive/pkg/auth/tokenexchange" "github.com/stacklok/toolhive/pkg/auth/upstreamswap" "github.com/stacklok/toolhive/pkg/authserver" "github.com/stacklok/toolhive/pkg/authz" @@ -22,7 +23,6 @@ import ( "github.com/stacklok/toolhive/pkg/bodylimit" cfg "github.com/stacklok/toolhive/pkg/config" "github.com/stacklok/toolhive/pkg/mcp" - "github.com/stacklok/toolhive/pkg/oauthproto/tokenexchange" "github.com/stacklok/toolhive/pkg/ratelimit" "github.com/stacklok/toolhive/pkg/recovery" "github.com/stacklok/toolhive/pkg/telemetry" diff --git a/pkg/runner/middleware_test.go b/pkg/runner/middleware_test.go index 27991a6902..0d850bce68 100644 --- a/pkg/runner/middleware_test.go +++ b/pkg/runner/middleware_test.go @@ -6,6 +6,8 @@ package runner import ( "bytes" "encoding/json" + "net/http" + "net/http/httptest" "os" "path/filepath" "testing" @@ -21,6 +23,7 @@ import ( "github.com/stacklok/toolhive/pkg/auth" "github.com/stacklok/toolhive/pkg/auth/awssts" "github.com/stacklok/toolhive/pkg/auth/obo" + "github.com/stacklok/toolhive/pkg/auth/tokenexchange" "github.com/stacklok/toolhive/pkg/auth/upstreamswap" "github.com/stacklok/toolhive/pkg/authserver" "github.com/stacklok/toolhive/pkg/authz" @@ -28,7 +31,6 @@ import ( "github.com/stacklok/toolhive/pkg/authz/authorizers/cedar" "github.com/stacklok/toolhive/pkg/bodylimit" "github.com/stacklok/toolhive/pkg/mcp" - "github.com/stacklok/toolhive/pkg/oauthproto/tokenexchange" "github.com/stacklok/toolhive/pkg/ratelimit" "github.com/stacklok/toolhive/pkg/recovery" "github.com/stacklok/toolhive/pkg/telemetry" @@ -558,6 +560,49 @@ func TestWithMiddlewareFromFlags_ExcludesHeaderForward(t *testing.T) { assert.Equal(t, map[string]string{"X-Key": "val"}, cfg.HeaderForward.AddPlaintextHeaders) } +func TestTokenExchangeRegistration(t *testing.T) { + t.Parallel() + + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + require.NoError(t, r.ParseForm()) + assert.Equal(t, "original-token", r.Form.Get("subject_token")) + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(`{"access_token":"exchanged-token","token_type":"Bearer","issued_token_type":"urn:ietf:params:oauth:token-type:access_token"}`)) + })) + t.Cleanup(server.Close) + + config := &RunConfig{TokenExchangeConfig: &tokenexchange.Config{TokenURL: server.URL}} + require.NoError(t, PopulateMiddlewareConfigs(config)) + serialized, err := json.Marshal(config) + require.NoError(t, err) + var restored RunConfig + require.NoError(t, json.Unmarshal(serialized, &restored)) + runner := NewRunner(&restored, nil) + for _, config := range restored.MiddlewareConfigs { + if config.Type != tokenexchange.MiddlewareType { + continue + } + factory, ok := runner.supportedMiddleware[config.Type] + require.True(t, ok) + require.NoError(t, factory(&config, runner)) + } + require.Len(t, runner.middlewares, 1) + require.IsType(t, &tokenexchange.Middleware{}, runner.middlewares[0]) + t.Cleanup(func() { require.NoError(t, runner.middlewares[0].Close()) }) + require.Len(t, runner.namedMiddlewares, 1) + assert.Equal(t, tokenexchange.MiddlewareType, runner.namedMiddlewares[0].Name) + + req := httptest.NewRequest(http.MethodGet, "/mcp", nil) + req.Header.Set("Authorization", "Bearer original-token") + req = req.WithContext(auth.WithIdentity(req.Context(), &auth.Identity{})) + rec := httptest.NewRecorder() + runner.namedMiddlewares[0].Function(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + assert.Equal(t, "Bearer exchanged-token", r.Header.Get("Authorization")) + w.WriteHeader(http.StatusNoContent) + })).ServeHTTP(rec, req) + assert.Equal(t, http.StatusNoContent, rec.Code) +} + func TestGetSupportedMiddlewareFactories(t *testing.T) { t.Parallel() diff --git a/pkg/transport/http.go b/pkg/transport/http.go index ccb0129970..bf2dbfd7a0 100644 --- a/pkg/transport/http.go +++ b/pkg/transport/http.go @@ -17,9 +17,9 @@ import ( "golang.org/x/oauth2" + "github.com/stacklok/toolhive/pkg/auth/tokenexchange" "github.com/stacklok/toolhive/pkg/container" rt "github.com/stacklok/toolhive/pkg/container/runtime" - "github.com/stacklok/toolhive/pkg/oauthproto/tokenexchange" transporterrors "github.com/stacklok/toolhive/pkg/transport/errors" "github.com/stacklok/toolhive/pkg/transport/middleware" "github.com/stacklok/toolhive/pkg/transport/proxy/transparent" diff --git a/pkg/transport/http_test.go b/pkg/transport/http_test.go index 650fae7c8f..507390232c 100644 --- a/pkg/transport/http_test.go +++ b/pkg/transport/http_test.go @@ -12,8 +12,8 @@ import ( "github.com/stretchr/testify/assert" "go.uber.org/mock/gomock" + "github.com/stacklok/toolhive/pkg/auth/tokenexchange" rt "github.com/stacklok/toolhive/pkg/container/runtime" - "github.com/stacklok/toolhive/pkg/oauthproto/tokenexchange" "github.com/stacklok/toolhive/pkg/transport/types" "github.com/stacklok/toolhive/pkg/transport/types/mocks" )