auth

package
v0.2.21 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2026 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMCPAuthRequired       = errors.New("mcp authorization required")
	ErrMCPInvalidAuthRequest = errors.New("invalid mcp auth request")
)
View Source
var ErrOAuthTokenNotFound = errors.New("oauth token not found")

Functions

func RedactError

func RedactError(err error, sensitiveValues []string) error

RedactError preserves an error chain while replacing configured secret values in the externally observable message.

func ValidateOAuthClientCredentialsSecret

func ValidateOAuthClientCredentialsSecret(raw string, requireClientSecret bool) error

Types

type AuthManager

type AuthManager struct {
	// contains filtered or unexported fields
}

func NewAuthManager

func NewAuthManager(
	secrets SecretResolver,
	options ...AuthManagerOption,
) *AuthManager

func (*AuthManager) BuildAuthHealth

func (m *AuthManager) BuildAuthHealth(
	ctx context.Context,
	config mcpServer.RuntimeConfig,
) MCPAuthHealth

func (*AuthManager) ClearAuthStatus

func (m *AuthManager) ClearAuthStatus(
	serverRef mcpServer.ServerID,
)

func (*AuthManager) ClearAuthStatuses

func (m *AuthManager) ClearAuthStatuses()

func (*AuthManager) ConnectionFailed

func (m *AuthManager) ConnectionFailed(
	ctx context.Context,
	config mcpServer.RuntimeConfig,
	err error,
)

func (*AuthManager) ConnectionSucceeded

func (m *AuthManager) ConnectionSucceeded(
	ctx context.Context,
	config mcpServer.RuntimeConfig,
)

func (*AuthManager) GetAuthStatus

func (m *AuthManager) GetAuthStatus(
	serverRef mcpServer.ServerID,
) (MCPAuthStatus, bool)

func (*AuthManager) PrepareConnection

func (m *AuthManager) PrepareConnection(
	ctx context.Context,
	config mcpServer.RuntimeConfig,
) (mcpConnection.PreparedConnection, error)

func (*AuthManager) SaveAuthStatus

func (m *AuthManager) SaveAuthStatus(
	ctx context.Context,
	status MCPAuthStatus,
) error

type AuthManagerOption

type AuthManagerOption func(*AuthManager)

func WithAuthHTTPClient

func WithAuthHTTPClient(
	client *http.Client,
) AuthManagerOption

func WithClientInfo

func WithClientInfo(
	name string,
	version string,
) AuthManagerOption

func WithOAuthAuthorizationBroker

func WithOAuthAuthorizationBroker(
	broker OAuthAuthorizationBroker,
) AuthManagerOption

func WithOAuthRedirectURL

func WithOAuthRedirectURL(
	redirectURL string,
) AuthManagerOption

func WithOAuthTokenStore

func WithOAuthTokenStore(
	store OAuthTokenStore,
) AuthManagerOption

type AuthStatusSink

type AuthStatusSink interface {
	SaveAuthStatus(
		ctx context.Context,
		status MCPAuthStatus,
	) error
}

type GrantType

type GrantType string
const (
	GrantTypeAuthorizationCode GrantType = "authorization_code"
	GrantTypeRefreshToken      GrantType = "refresh_token"
)

type MCPAuthHealth

type MCPAuthHealth struct {
	Server   mcpServer.ServerID        `json:"server"`
	AuthMode mcpServer.MCPHTTPAuthMode `json:"authMode"`
	State    MCPAuthHealthState        `json:"state"`

	Configured bool `json:"configured"`

	Resource  string     `json:"resource,omitempty"`
	Scopes    []string   `json:"scopes,omitempty"`
	ExpiresAt *time.Time `json:"expiresAt,omitempty"`

	AuthorizationPending   bool   `json:"authorizationPending,omitempty"`
	AuthorizationURL       string `json:"authorizationURL,omitempty"`
	AuthorizationExpiresAt string `json:"authorizationExpiresAt,omitempty"`

	OAuthRedirectURL        string `json:"oauthRedirectURL,omitempty"`
	OAuthLoopbackListenAddr string `json:"oauthLoopbackListenAddr,omitempty"`
	OAuthLoopbackReady      *bool  `json:"oauthLoopbackReady,omitempty"`
	OAuthLoopbackError      string `json:"oauthLoopbackError,omitempty"`

	LastError string `json:"lastError,omitempty"`
}

type MCPAuthHealthState

type MCPAuthHealthState string
const (
	MCPAuthHealthStateNotRequired          MCPAuthHealthState = "notRequired"
	MCPAuthHealthStateNotConfigured        MCPAuthHealthState = "notConfigured"
	MCPAuthHealthStateAuthorizationNeeded  MCPAuthHealthState = "authorizationNeeded"
	MCPAuthHealthStateAuthorizationPending MCPAuthHealthState = "authorizationPending"
	MCPAuthHealthStateAuthorized           MCPAuthHealthState = "authorized"
	MCPAuthHealthStateExpired              MCPAuthHealthState = "expired"
	MCPAuthHealthStateInsufficientScope    MCPAuthHealthState = "insufficientScope"
	MCPAuthHealthStateError                MCPAuthHealthState = "error"
)

type MCPAuthSettings

type MCPAuthSettings struct {
	// Empty means a random loopback port is used for the current process.
	OAuthLoopbackListenAddr string `json:"oauthLoopbackListenAddr,omitempty"`
}

type MCPAuthState

type MCPAuthState string
const (
	MCPAuthStateNotRequired       MCPAuthState = "notRequired"
	MCPAuthStateRequired          MCPAuthState = "required"
	MCPAuthStateAuthorized        MCPAuthState = "authorized"
	MCPAuthStateExpired           MCPAuthState = "expired"
	MCPAuthStateInsufficientScope MCPAuthState = "insufficientScope"
	MCPAuthStateError             MCPAuthState = "error"
)

type MCPAuthStatus

type MCPAuthStatus struct {
	Server   mcpServer.ServerID        `json:"server"`
	AuthMode mcpServer.MCPHTTPAuthMode `json:"authMode"`
	State    MCPAuthState              `json:"state"`

	Scopes              []string   `json:"scopes,omitempty"`
	ExpiresAt           *time.Time `json:"expiresAt,omitempty"`
	LastError           string     `json:"lastError,omitempty"`
	AuthorizationServer string     `json:"authorizationServer,omitempty"`
	Resource            string     `json:"resource,omitempty"`
}

type MCPOAuthAuthorization

type MCPOAuthAuthorization struct {
	Server           mcpServer.ServerID `json:"server"`
	AuthorizationURL string             `json:"authorizationURL"`
	ExpiresAt        string             `json:"expiresAt,omitempty"`
}

type OAuthAuthorizationBroker

type OAuthAuthorizationBroker interface {
	FetchAuthorizationCode(
		ctx context.Context,
		request OAuthAuthorizationRequest,
	) (*OAuthAuthorizationResult, error)
}

type OAuthAuthorizationRequest

type OAuthAuthorizationRequest struct {
	Server           mcpServer.ServerID
	AuthorizationURL string
}

type OAuthAuthorizationResult

type OAuthAuthorizationResult struct {
	Code  string
	State string
	Iss   string
}

type OAuthLoopbackBroker

type OAuthLoopbackBroker struct {
	// contains filtered or unexported fields
}

func (*OAuthLoopbackBroker) Cancel

func (b *OAuthLoopbackBroker) Cancel(
	server mcpServer.ServerID,
) bool

func (*OAuthLoopbackBroker) Close

func (b *OAuthLoopbackBroker) Close() error

func (*OAuthLoopbackBroker) FetchAuthorizationCode

func (*OAuthLoopbackBroker) ListenAddr

func (b *OAuthLoopbackBroker) ListenAddr() string

func (*OAuthLoopbackBroker) Pending

func (*OAuthLoopbackBroker) Readiness

func (b *OAuthLoopbackBroker) Readiness() (ready bool, errStr string)

func (*OAuthLoopbackBroker) RedirectURL

func (b *OAuthLoopbackBroker) RedirectURL() string

func (*OAuthLoopbackBroker) ServeHTTP

func (b *OAuthLoopbackBroker) ServeHTTP(w http.ResponseWriter, r *http.Request)

type OAuthLoopbackBrokerOptions

type OAuthLoopbackBrokerOptions struct {
	TTL          time.Duration
	CallbackPath string
	Logger       *slog.Logger
	ListenAddr   string
}

type OAuthTokenStore

type OAuthTokenStore interface {
	LoadOAuthToken(ctx context.Context, base MCPAuthStatus) (*oauth2.Token, error)
	SaveOAuthToken(ctx context.Context, base MCPAuthStatus, tok *oauth2.Token) error
	DeleteOAuthToken(ctx context.Context, base MCPAuthStatus) error
}

type SecretRedactor

type SecretRedactor struct {
	// contains filtered or unexported fields
}

func NewSecretRedactor

func NewSecretRedactor(resolved mcpConnection.PreparedConnection) *SecretRedactor

func (*SecretRedactor) Redact

func (r *SecretRedactor) Redact(s string) string

type SecretResolver

type SecretResolver interface {
	ResolveSecret(ctx context.Context, ref string) (string, error)
}

type StaticSecretResolver

type StaticSecretResolver map[string]string

func (StaticSecretResolver) ResolveSecret

func (r StaticSecretResolver) ResolveSecret(ctx context.Context, ref string) (string, error)

Jump to

Keyboard shortcuts

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