auth

package
v8.0.71 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 38 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AntigravityModelBaseURLDaily is the default Cloud Code endpoint for Antigravity model discovery.
	AntigravityModelBaseURLDaily = "https://daily-cloudcode-pa.googleapis.com"
	// AntigravityModelsPath is the upstream path for per-account model capability discovery.
	AntigravityModelsPath = "/v1internal:fetchAvailableModels"
	// AntigravityPersistedHintsMetaKey is the auth metadata key storing persisted model capability hints.
	AntigravityPersistedHintsMetaKey = "antigravity_capability_hints"
)
View Source
const AntigravityDefaultCallbackPort = antigravity.CallbackPort

AntigravityDefaultCallbackPort is the default local port used for Antigravity OAuth loopback callbacks.

Variables

View Source
var ErrRefreshNotSupported = errors.New("cliproxy auth: refresh not supported")

Functions

func AntigravityDefaultCallbackURI

func AntigravityDefaultCallbackURI() string

AntigravityDefaultCallbackURI returns the default loopback redirect URI for Antigravity OAuth.

func AntigravityRequestUserAgent added in v8.0.33

func AntigravityRequestUserAgent(userAgent string) string

AntigravityRequestUserAgent returns the User-Agent for Antigravity runtime requests, falling back to AntigravityUserAgent when userAgent is empty.

func AntigravityUserAgent

func AntigravityUserAgent() string

AntigravityUserAgent returns the canonical User-Agent string used by the Antigravity Hub family.

func BuildAntigravityAuth

func BuildAntigravityAuth(tokenResp *AntigravityTokenResponse, email, projectID string) *coreauth.Auth

BuildAntigravityAuth constructs an in-memory *coreauth.Auth object from token credentials and metadata.

func BuildAntigravityAuthURL

func BuildAntigravityAuthURL(state, redirectURI string) string

BuildAntigravityAuthURL generates the OAuth authorization URL for Antigravity. If redirectURI is empty, the default loopback callback URI is used.

func BuildPersistedAntigravityCapabilityHints added in v8.0.54

func BuildPersistedAntigravityCapabilityHints(project, endpoint string, hints AntigravityModelCapabilityHints) map[string]any

BuildPersistedAntigravityCapabilityHints serializes capability hints for storage in auth metadata. It returns nil when hints.ModelIDs is nil so unknown catalogs are never persisted as authoritative empty sets.

func CompleteAntigravityOAuth

func CompleteAntigravityOAuth(ctx context.Context, code, redirectURI string, httpClient *http.Client) (*coreauth.Auth, error)

CompleteAntigravityOAuth performs code exchange, user identity retrieval, and GCP project discovery using an injected HTTP client, returning an assembled *coreauth.Auth without touching the filesystem.

func FetchAntigravityAvailableModels added in v8.0.54

FetchAntigravityAvailableModels performs a single-shot POST /v1internal:fetchAvailableModels request and parses the returned per-account model catalog and webSearchModelIds.

func FetchAntigravityProjectID

func FetchAntigravityProjectID(ctx context.Context, accessToken string, httpClient *http.Client) (string, error)

FetchAntigravityProjectID exposes project discovery for external callers.

func FetchAntigravityUserInfo

func FetchAntigravityUserInfo(ctx context.Context, accessToken string, httpClient *http.Client) (string, error)

FetchAntigravityUserInfo retrieves the user email address using the given access token.

func GetTokenStore

func GetTokenStore() coreauth.Store

GetTokenStore returns the globally registered token store.

func NormalizeAntigravityModelID added in v8.0.54

func NormalizeAntigravityModelID(modelID string) string

NormalizeAntigravityModelID normalizes an Antigravity model identifier for case-insensitive matching.

func RegisterPluginAuthParser

func RegisterPluginAuthParser(parser PluginAuthParser)

RegisterPluginAuthParser registers the current plugin auth parser.

func RegisterTokenStore

func RegisterTokenStore(store coreauth.Store)

RegisterTokenStore sets the global token store used by the authentication helpers.

func StartAntigravityVersionUpdater added in v8.0.33

func StartAntigravityVersionUpdater(ctx context.Context)

StartAntigravityVersionUpdater starts background refresh for the Antigravity Hub version. Pass a process-lifetime ctx; it runs only once and is not auto-started by SDK packages.

Types

type AntigravityAuthenticator

type AntigravityAuthenticator struct{}

AntigravityAuthenticator implements OAuth login for the antigravity provider.

func (AntigravityAuthenticator) Login

Login launches a local OAuth flow to obtain antigravity tokens and persists them.

func (AntigravityAuthenticator) Provider

func (AntigravityAuthenticator) Provider() string

Provider returns the provider key for antigravity.

func (AntigravityAuthenticator) RefreshLead

func (AntigravityAuthenticator) RefreshLead() *time.Duration

RefreshLead instructs the manager to refresh 30 minutes before expiry.

type AntigravityModelCapabilityHints added in v8.0.54

type AntigravityModelCapabilityHints struct {
	WebSearchModelIDs map[string]struct{}
	// Nil means unknown; an empty non-nil set is an authoritative empty catalog.
	ModelIDs map[string]struct{}
}

AntigravityModelCapabilityHints holds normalized per-account model IDs and web-search capability IDs.

func ParseAntigravityModelCapabilityHints added in v8.0.54

func ParseAntigravityModelCapabilityHints(body []byte) (AntigravityModelCapabilityHints, bool)

ParseAntigravityModelCapabilityHints decodes a fetchAvailableModels response payload using ojson.

func ParsePersistedAntigravityCapabilityHints added in v8.0.54

func ParsePersistedAntigravityCapabilityHints(metadata map[string]any, expectedProject, expectedEndpoint string) (AntigravityModelCapabilityHints, bool)

ParsePersistedAntigravityCapabilityHints extracts and validates persisted capability hints from auth metadata.

func (AntigravityModelCapabilityHints) Clone added in v8.0.54

Clone returns a deep copy of the capability hints.

type AntigravityModelProbeRequest added in v8.0.54

type AntigravityModelProbeRequest struct {
	BaseURLs    []string
	ProxyURL    string
	AccessToken string
	ProjectID   string
	UserAgent   string
}

AntigravityModelProbeRequest configures a single-shot fetchAvailableModels probe.

type AntigravityProbeStatus added in v8.0.54

type AntigravityProbeStatus int

AntigravityProbeStatus classifies the outcome of an Antigravity model discovery request.

const (
	AntigravityProbeStatusSuccess AntigravityProbeStatus = iota
	AntigravityProbeStatusAuthError
	AntigravityProbeStatusTransientError
)

type AntigravityTokenResponse

type AntigravityTokenResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
	ExpiresIn    int64  `json:"expires_in"`
	TokenType    string `json:"token_type"`
}

AntigravityTokenResponse captures the tokens returned by Antigravity OAuth exchange.

func ExchangeAntigravityCode

func ExchangeAntigravityCode(ctx context.Context, code, redirectURI string, httpClient *http.Client) (*AntigravityTokenResponse, error)

ExchangeAntigravityCode exchanges an authorization code for access and refresh tokens.

type Authenticator

type Authenticator interface {
	Provider() string
	Login(ctx context.Context, cfg *config.Config, opts *LoginOptions) (*coreauth.Auth, error)
	RefreshLead() *time.Duration
}

Authenticator manages login and optional refresh flows for a provider.

func NewAntigravityAuthenticator

func NewAntigravityAuthenticator() Authenticator

NewAntigravityAuthenticator constructs a new authenticator instance.

func NewKimiAIAuthenticator

func NewKimiAIAuthenticator() Authenticator

NewKimiAIAuthenticator constructs a new Kimi authenticator for kimi.ai with provider "kimi-ai".

func NewKimiAIDotAuthenticator

func NewKimiAIDotAuthenticator() Authenticator

NewKimiAIDotAuthenticator constructs a new Kimi authenticator for kimi.ai with provider "kimi.ai".

func NewKimiAuthenticator

func NewKimiAuthenticator() Authenticator

NewKimiAuthenticator constructs a new Kimi authenticator for kimi.com.

func NewMetaAuthenticator

func NewMetaAuthenticator() Authenticator

NewMetaAuthenticator constructs a new Meta authenticator.

func NewXAIAuthenticator

func NewXAIAuthenticator() Authenticator

NewXAIAuthenticator constructs a new xAI authenticator.

type ClaudeAuthenticator

type ClaudeAuthenticator struct {
	CallbackPort int
}

ClaudeAuthenticator implements the OAuth login flow for Anthropic Claude accounts.

func NewClaudeAuthenticator

func NewClaudeAuthenticator() *ClaudeAuthenticator

NewClaudeAuthenticator constructs a Claude authenticator with default settings.

func (*ClaudeAuthenticator) Login

func (*ClaudeAuthenticator) Provider

func (a *ClaudeAuthenticator) Provider() string

func (*ClaudeAuthenticator) RefreshLead

func (a *ClaudeAuthenticator) RefreshLead() *time.Duration

type CodexAuthenticator

type CodexAuthenticator struct {
	CallbackPort int
}

CodexAuthenticator implements the OAuth login flow for Codex accounts.

func NewCodexAuthenticator

func NewCodexAuthenticator() *CodexAuthenticator

NewCodexAuthenticator constructs a Codex authenticator with default settings.

func (*CodexAuthenticator) Login

func (*CodexAuthenticator) Provider

func (a *CodexAuthenticator) Provider() string

func (*CodexAuthenticator) RefreshLead

func (a *CodexAuthenticator) RefreshLead() *time.Duration

type DevinAuthenticator

type DevinAuthenticator struct {
	CallbackPort int
	AuthService  *devinauth.DevinAuthService
}

DevinAuthenticator implements OAuth and headless authentication for Devin / Cognition.

func NewDevinAuthenticator

func NewDevinAuthenticator() *DevinAuthenticator

NewDevinAuthenticator constructs a new Devin authenticator instance.

func (*DevinAuthenticator) Login

Login executes the interactive browser-based or headless manual authentication flow for Devin.

func (*DevinAuthenticator) Provider

func (a *DevinAuthenticator) Provider() string

Provider returns the unique provider identifier for Devin.

func (*DevinAuthenticator) RefreshLead

func (a *DevinAuthenticator) RefreshLead() *time.Duration

RefreshLead returns nil since Devin OAuth tokens are permanent session tokens.

type EmailRequiredError

type EmailRequiredError struct {
	Prompt string
}

EmailRequiredError indicates that the calling context must provide an email or alias.

func (*EmailRequiredError) Error

func (e *EmailRequiredError) Error() string

type FileTokenStore

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

FileTokenStore persists token records and auth metadata using the filesystem as backing storage.

func NewFileTokenStore

func NewFileTokenStore() *FileTokenStore

NewFileTokenStore creates a token store that saves credentials to disk through the TokenStorage implementation embedded in the token record.

func (*FileTokenStore) Delete

func (s *FileTokenStore) Delete(ctx context.Context, id string) error

Delete removes the auth file.

func (*FileTokenStore) List

func (s *FileTokenStore) List(ctx context.Context) ([]*cliproxyauth.Auth, error)

List enumerates all auth JSON files under the configured directory.

func (*FileTokenStore) RefreshJournalFor added in v8.0.59

func (s *FileTokenStore) RefreshJournalFor(auth *coreauth.Auth) (codex.RefreshJournal, error)

RefreshJournalFor snapshots the authoritative directory for this refresh. A FileTokenStore may use explicit credential paths without configuring baseDir.

func (*FileTokenStore) Save

func (s *FileTokenStore) Save(ctx context.Context, auth *cliproxyauth.Auth) (string, error)

Save persists token storage and metadata to the resolved auth file path.

func (*FileTokenStore) SetBaseDir

func (s *FileTokenStore) SetBaseDir(dir string)

SetBaseDir updates the default directory used for auth JSON persistence when no explicit path is provided.

type KimiAuthenticator

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

KimiAuthenticator implements the OAuth device flow login for Kimi (Moonshot AI).

func (KimiAuthenticator) Login

Login initiates the Kimi device flow authentication.

func (KimiAuthenticator) Provider

func (a KimiAuthenticator) Provider() string

Provider returns the provider key for kimi.

func (KimiAuthenticator) RefreshLead

func (KimiAuthenticator) RefreshLead() *time.Duration

RefreshLead returns the duration before token expiry when refresh should occur. Kimi tokens expire and need to be refreshed before expiry.

type LoginOptions

type LoginOptions struct {
	NoBrowser    bool
	ProjectID    string
	CallbackPort int
	Metadata     map[string]string
	Prompt       func(prompt string) (string, error)
	ProxyURL     string
}

LoginOptions captures generic knobs shared across authenticators. Provider-specific logic can inspect Metadata for extra parameters.

type Manager

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

Manager aggregates authenticators and coordinates persistence via a token store.

func NewManager

func NewManager(store coreauth.Store, authenticators ...Authenticator) *Manager

NewManager constructs a manager with the provided token store and authenticators. If store is nil, the caller must set it later using SetStore.

func (*Manager) Login

func (m *Manager) Login(ctx context.Context, provider string, cfg *config.Config, opts *LoginOptions) (*coreauth.Auth, string, error)

Login executes the provider login flow and persists the resulting auth record.

func (*Manager) Register

func (m *Manager) Register(a Authenticator)

Register adds or replaces an authenticator keyed by its provider identifier.

func (*Manager) SetStore

func (m *Manager) SetStore(store coreauth.Store)

SetStore updates the token store used for persistence.

type MetaAuthenticator

type MetaAuthenticator struct{}

MetaAuthenticator implements the Meta Muse OAuth device-code flow.

func (MetaAuthenticator) Login

Login launches the OAuth device-code flow to obtain Meta tokens and persists them.

func (MetaAuthenticator) Provider

func (MetaAuthenticator) Provider() string

Provider returns the provider key for Meta.

func (MetaAuthenticator) RefreshLead

func (MetaAuthenticator) RefreshLead() *time.Duration

RefreshLead instructs the manager on token refresh lead time. Meta credentials do not advertise an API key expiration, so scheduled refresh is disabled and recovery is triggered on demand (e.g. on 401 or request preparation).

type PluginAuthParser

type PluginAuthParser interface {
	ParseAuth(context.Context, pluginapi.AuthParseRequest) (*cliproxyauth.Auth, bool, error)
}

PluginAuthParser parses auth JSON owned by plugin providers.

type PluginMultiAuthParser

type PluginMultiAuthParser interface {
	ParseAuths(context.Context, pluginapi.AuthParseRequest) ([]*cliproxyauth.Auth, bool, error)
}

PluginMultiAuthParser expands one auth JSON payload into multiple plugin auth records. Returning handled=true with an empty slice means the plugin intentionally suppresses built-in parsing.

type XAIAuthenticator

type XAIAuthenticator struct{}

XAIAuthenticator implements the xAI Grok OAuth device-code flow.

func (XAIAuthenticator) Login

Login launches the OAuth device-code flow to obtain xAI tokens and persists them.

func (XAIAuthenticator) Provider

func (XAIAuthenticator) Provider() string

Provider returns the provider key for xAI.

func (XAIAuthenticator) RefreshLead

func (XAIAuthenticator) RefreshLead() *time.Duration

RefreshLead instructs the manager to refresh before token expiry.

Jump to

Keyboard shortcuts

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