cliauth

package
v0.5.13 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotLoggedIn = errors.New("cliauth: not logged in")

ErrNotLoggedIn is returned when no credentials exist for the requested host.

Functions

func CallbackPort

func CallbackPort(addr net.Addr) int

CallbackPort returns a TCP port from addr when available.

func DefaultCredPath

func DefaultCredPath(issuer string) (string, error)

DefaultCredPath returns the standard issuer-scoped credentials path.

func HostFromIssuer

func HostFromIssuer(issuer string) (string, error)

HostFromIssuer returns the canonical host key for an issuer URL.

Types

type CredStore

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

CredStore persists OAuth credentials for one or more hosts.

func NewCredStore

func NewCredStore(path string) *CredStore

NewCredStore returns a store backed by path.

func (*CredStore) DeleteAll

func (s *CredStore) DeleteAll() error

DeleteAll removes the entire credentials file.

func (*CredStore) DeleteHost

func (s *CredStore) DeleteHost(host string) error

DeleteHost removes one host. If it was current, current advances by sort order.

func (*CredStore) Hosts

func (s *CredStore) Hosts() ([]string, error)

Hosts returns sorted host keys.

func (*CredStore) LoadCurrent

func (s *CredStore) LoadCurrent() (string, Credentials, error)

LoadCurrent returns the current host and its credentials.

func (*CredStore) LoadHost

func (s *CredStore) LoadHost(host string) (Credentials, error)

LoadHost returns the credentials for host.

func (*CredStore) Path

func (s *CredStore) Path() string

Path returns the underlying credentials file path.

func (*CredStore) SaveHost

func (s *CredStore) SaveHost(host string, creds Credentials) error

SaveHost upserts one host's credentials.

func (*CredStore) UseHost

func (s *CredStore) UseHost(host string) error

UseHost flips Current to host.

type Credentials

type Credentials struct {
	Issuer       string    `json:"issuer"`
	ClientID     string    `json:"client_id"`
	RedirectURIs []string  `json:"redirect_uris,omitempty"`
	AccessToken  string    `json:"access_token,omitempty"`
	RefreshToken string    `json:"refresh_token,omitempty"`
	ExpiresAt    time.Time `json:"expires_at,omitzero"`
	Scope        string    `json:"scope,omitempty"`
}

Credentials is one issuer host's persisted OAuth state.

func (Credentials) NeedsRefresh

func (c Credentials) NeedsRefresh() bool

NeedsRefresh reports whether the access token should be refreshed before use.

type Endpoints

type Endpoints struct {
	Authorization string
	Token         string
	Revocation    string
	Registration  string
}

Endpoints contains OAuth endpoints discovered from the issuer or supplied by callers.

type Login

type Login struct {
	Issuer     string
	Store      *CredStore
	HTTPClient *http.Client
	OpenURL    func(url string) error
	Endpoints  Endpoints
}

Login orchestrates the OAuth/PKCE flow against an MCP server.

func NewLogin

func NewLogin(opts LoginOptions) (*Login, error)

NewLogin returns a Login configured for issuer.

func (*Login) GetAccessToken

func (l *Login) GetAccessToken(ctx context.Context) (string, error)

GetAccessToken returns a valid access token, refreshing first if needed.

func (*Login) Logout

func (l *Login) Logout(ctx context.Context) error

Logout removes the stored credentials for l.Issuer's host.

func (*Login) RunLoopback

func (l *Login) RunLoopback(ctx context.Context, opts LoopbackOptions) error

RunLoopback performs the auto-browser PKCE loopback flow.

func (*Login) RunPasteRedirect

func (l *Login) RunPasteRedirect(ctx context.Context, opts PasteOptions) error

RunPasteRedirect performs a PKCE flow where the user pastes the redirect URL.

type LoginOptions

type LoginOptions struct {
	Issuer     string
	CredPath   string
	Store      *CredStore
	HTTPClient *http.Client
	OpenURL    func(url string) error
	Endpoints  Endpoints
}

LoginOptions configures a CLI OAuth helper.

type LoopbackOptions

type LoopbackOptions struct {
	Port  int
	Scope string
}

LoopbackOptions configures the auto-browser PKCE loopback flow.

type PasteOptions

type PasteOptions struct {
	Port  int
	Scope string
	In    io.Reader
	Out   io.Writer
}

PasteOptions configures the paste-redirect PKCE flow.

Jump to

Keyboard shortcuts

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