Documentation
¶
Overview ¶
Package oauth acquires, caches, and refreshes OAuth2 access tokens for clic. It is deliberately free of any clic-internal dependencies (callers map their own auth config onto oauth.Config), so it can be used from both the headless CLI and the interactive studio without import cycles.
Index ¶
Constants ¶
const ( FlowClientCredentials = "client_credentials" FlowAuthorizationCode = "authorization_code" )
Grant flows clic can perform. The string values match provider.Flow* so the caller-side mapping is a direct copy.
const DefaultRedirectURL = "http://127.0.0.1:9799/callback"
DefaultRedirectURL is the loopback redirect used for the authorization-code flow when the caller does not override it. The fixed port lets it be pre-registered with the OAuth provider.
Variables ¶
var ErrLoginRequired = errors.New("oauth2: interactive login required")
ErrLoginRequired is returned by Token when a valid token is not cached and the configured flow needs interactive login (authorization_code). Callers should run Login (e.g. via `clic login`) to obtain one.
Functions ¶
func CachedToken ¶
CachedToken returns the cached access token if one is present and unexpired, without any network call. The studio uses it to seed auth state on launch.
func HasValidToken ¶
HasValidToken reports whether a non-expired token is already cached, without fetching or refreshing. The studio uses it to show auth status at a glance.
func Login ¶
Login obtains a token interactively when needed and caches it: a direct fetch for client-credentials, or the browser-based authorization-code + PKCE flow. opener may be nil to use the default system browser.
func Token ¶
Token returns a valid access token without any interaction: it reuses a cached token, silently refreshes an expired one when a refresh token is present, and otherwise fetches a fresh token for the non-interactive client-credentials flow. For authorization_code with no usable cached token it returns ErrLoginRequired.
Types ¶
type Config ¶
type Config struct {
Flow string
ClientID string
ClientSecret string
AuthURL string // authorization endpoint (authorization_code)
TokenURL string
Scopes []string
RedirectURL string // loopback redirect (authorization_code); DefaultRedirectURL if empty
}
Config is everything oauth needs to obtain a token for one credential set.