Documentation
¶
Overview ¶
Package oauth is the driven adapter for upstream OAuth: it builds the go-sdk OAuthHandlers (client-credentials via extauth, auth-code+PKCE via auth.AuthorizationCodeHandler) and owns the on-disk token store that lets `serve` run unattended after `toolhost mcp auth` granted once.
Index ¶
- Constants
- func AuthorizeOnce(ctx context.Context, endpoint string, h auth.OAuthHandler, hc *http.Client) error
- func LoopbackFetcher(redirectURL string, open func(string) error, out io.Writer) auth.AuthorizationCodeFetcher
- func NewHandler(ctx context.Context, name string, a *config.Auth, store *Store, ...) (auth.OAuthHandler, error)
- func StorePath(configPath string) string
- type Store
- type StoredToken
Constants ¶
const DefaultRedirectURL = "http://127.0.0.1:8484/callback"
DefaultRedirectURL is the loopback callback the authorization flow listens on. A fixed port keeps preregistered and DCR'd redirect URIs stable — CLIs do this everywhere (gh, az, gcloud all do).
Variables ¶
This section is empty.
Functions ¶
func AuthorizeOnce ¶
func AuthorizeOnce(ctx context.Context, endpoint string, h auth.OAuthHandler, hc *http.Client) error
AuthorizeOnce drives a handler against a real 401 — the same probe the streamable transport performs internally on connect, invoked explicitly so `toolhost mcp auth` (and SSE, which has no OAuthHandler seam) can run the flow.
func LoopbackFetcher ¶
func LoopbackFetcher(redirectURL string, open func(string) error, out io.Writer) auth.AuthorizationCodeFetcher
LoopbackFetcher implements auth.AuthorizationCodeFetcher the way CLI OAuth always works: bind the loopback address the AS will redirect to, hand the authorization URL to the user's browser (and print it — the open is best-effort), wait for the callback carrying code+state(+iss per RFC 9207).
func NewHandler ¶
func NewHandler(ctx context.Context, name string, a *config.Auth, store *Store, interactive bool, open func(string) error, out io.Writer) (auth.OAuthHandler, error)
NewHandler builds the go-sdk OAuthHandler for a backend's auth block — nil for auth modes that don't need one (none/bearer get their header from the base client instead). interactive=false installs a fetcher that fails fast ("run toolhost mcp auth") so serve/discover never pop a browser. open is the browser launcher — nil picks the platform default.
Types ¶
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store persists upstream tokens in <config dir>/toolhost_tokens.json (0600).
func (*Store) Get ¶
func (s *Store) Get(name string) *StoredToken
Get returns the stored token for a backend, or nil.
type StoredToken ¶
type StoredToken struct {
AccessToken string `json:"access_token"`
TokenType string `json:"token_type,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
Expiry time.Time `json:"expiry,omitempty"`
Scopes []string `json:"scopes,omitempty"`
TokenURL string `json:"token_url,omitempty"`
ClientID string `json:"client_id,omitempty"`
ClientSecret string `json:"client_secret,omitempty"`
}
StoredToken is one backend's persisted grant, including enough of the client registration (id/secret/token endpoint) to rebuild a refreshing token source on the next run without re-authorizing.