oauthclient

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCredentialWritesQuiesced = errors.New("OAuth credential writes are quiesced")
View Source
var ErrNotFound = errors.New("oauth session not found")

ErrNotFound reports that no mcpx-owned OAuth session exists for a server.

Functions

func CredentialKey

func CredentialKey(serverURL string) string

CredentialKey returns a stable, non-secret key for a protected resource.

func NewHandler

func NewHandler(ctx context.Context, opts HandlerOptions) (auth.OAuthHandler, error)

NewHandler restores a saved session when present and configures secure refresh persistence. Interactive authorization only occurs when AllowLogin is true.

func QuiesceCredentialWrites

func QuiesceCredentialWrites(handler auth.OAuthHandler)

QuiesceCredentialWrites prevents an OAuth handler from persisting any token after this call returns, including from SDK reconnect goroutines that outlive transport Close.

func SessionHasIssuerBinding

func SessionHasIssuerBinding(session *Session) bool

SessionHasIssuerBinding reports whether a saved OAuth grant is bound to the authorization server that issued its client credentials.

func SessionHasUsableToken

func SessionHasUsableToken(session *Session) bool

SessionHasUsableToken reports whether a saved session can authenticate now or refresh without another interactive login.

func SessionScopesCompatible

func SessionScopesCompatible(session *Session, configured []string) bool

SessionScopesCompatible reports whether a saved OAuth grant can satisfy the explicitly configured scopes. An empty configured set accepts the grant's discovered scopes, matching NewHandler behavior.

Types

type HandlerOptions

type HandlerOptions struct {
	ServerURL         string
	RedirectURL       string
	Fetcher           auth.AuthorizationCodeFetcher
	Store             Store
	Scopes            []string
	ClientMetadataURL string
	AllowLogin        bool
}

HandlerOptions configures an MCP OAuth authorization-code handler.

type LoopbackReceiver

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

LoopbackReceiver owns a temporary loopback callback listener for an interactive OAuth login.

func NewLoopbackReceiver

func NewLoopbackReceiver(output io.Writer) (*LoopbackReceiver, error)

NewLoopbackReceiver binds an unpredictable local port and starts the OAuth callback server. It never accepts non-loopback connections.

func (*LoopbackReceiver) Close

func (r *LoopbackReceiver) Close() error

Close stops the callback server.

func (*LoopbackReceiver) Fetch

Fetch prints the authorization URL and waits for the redirect. Requiring the user to open it prevents an untrusted authorization server from driving the system browser through redirects into a local or private network.

func (*LoopbackReceiver) RedirectURL

func (r *LoopbackReceiver) RedirectURL() string

RedirectURL is the exact loopback URI registered with the authorization server.

type Session

type Session struct {
	Config storedOAuthConfig `json:"config"`
	Token  oauth2.Token      `json:"token"`
}

Session is the minimum state needed to refresh and reuse an OAuth grant.

type Store

type Store interface {
	Load(key string) (*Session, error)
	Save(key string, session *Session) error
	Delete(key string) error
}

Store is the credential boundary used by OAuth clients. Implementations must keep serialized sessions out of repository and ordinary config files.

func NewKeyringStore

func NewKeyringStore() Store

NewKeyringStore returns the production OS credential-store adapter.

Jump to

Keyboard shortcuts

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