oauth

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 auth` granted once.

Index

Constants

View Source
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 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 auth") so serve/discover never pop a browser. open is the browser launcher — nil picks the platform default.

func StorePath

func StorePath(configPath string) string

StorePath is where upstream tokens live: beside the config file, never in it — the config is shareable, the tokens are credentials.

Types

type Store

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

Store persists upstream tokens in <config dir>/toolhost_tokens.json (0600).

func OpenStore

func OpenStore(path string) (*Store, error)

func (*Store) Delete

func (s *Store) Delete(name string) error

Delete removes a backend's token (revoke/re-auth).

func (*Store) Get

func (s *Store) Get(name string) *StoredToken

Get returns the stored token for a backend, or nil.

func (*Store) Path

func (s *Store) Path() string

func (*Store) Put

func (s *Store) Put(name string, tok *StoredToken) error

Put records or replaces a backend's token and flushes the file.

func (*Store) Source

func (s *Store) Source(ctx context.Context, name string) oauth2.TokenSource

Source returns a token source for a stored grant, refreshing and re-persisting as needed. Nil when nothing is stored — callers treat nil as "needs `toolhost auth`".

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.

Jump to

Keyboard shortcuts

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