transport

package
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2025 License: Apache-2.0 Imports: 16 Imported by: 4

Documentation

Overview

Package transport implements an http.RoundTripper that performs the OAuth 2.1 [Protected Resource Metadata](https://www.rfc-editor.org/rfc/rfc9728) discovery, token acquisition and automatic request retry logic required by MCP when a server challenges the client with `401 Unauthorized`.

The RoundTripper integrates seamlessly with the higher-level `auth.Authorizer` interceptor but can also be used directly to secure arbitrary HTTP traffic.

Index

Constants

View Source
const (
	ContextFlowOptionKey contextScopeKey = "authFlowOptions"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*RoundTripper)

func WithAuthFlow

func WithAuthFlow(flow flow.AuthFlow) Option

WithAuthFlow sets auth flow

func WithAuthorizationExchangeHeader added in v0.2.7

func WithAuthorizationExchangeHeader(name string) Option

func WithBackendForFrontendAuth added in v0.2.7

func WithBackendForFrontendAuth() Option

func WithGlobalResource

func WithGlobalResource(global *authorization.Authorization) Option

WithGlobalResource sets global resource

func WithStore

func WithStore(store store.Store) Option

WithStore sets store

type RoundTripper

type RoundTripper struct {
	Global *authorization.Authorization
	// contains filtered or unexported fields
}

func New

func New(options ...Option) (*RoundTripper, error)

func (*RoundTripper) IdToken

func (r *RoundTripper) IdToken(ctx context.Context, token *oauth2.Token, resourceMetadata *meta.ProtectedResourceMetadata) (*oauth2.Token, error)

func (*RoundTripper) ProtectedResourceToken

func (r *RoundTripper) ProtectedResourceToken(ctx context.Context, resourceMetadata *meta.ProtectedResourceMetadata, scope string) (*oauth2.Token, error)

func (*RoundTripper) RoundTrip

func (r *RoundTripper) RoundTrip(req *http.Request) (*http.Response, error)

func (*RoundTripper) Store

func (r *RoundTripper) Store() store.Store

func (*RoundTripper) Token

func (r *RoundTripper) Token(ctx context.Context, resp *http.Response) (*oauth2.Token, error)

type Scopper

type Scopper interface {
	Scope(request *http.Request) string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL