Documentation
¶
Index ¶
- func DefaultClientID() string
- func EmitEvent(ev HeadlessEvent)
- func SwapEmitWriter(w io.Writer) io.Writer
- type AuthDeps
- type AuthResult
- type CallbackRequest
- type Client
- type DeviceCodeResponse
- type DeviceTokenResponse
- type HeadlessEvent
- type OAuthConfig
- type OAuthFlowResult
- type OAuthResult
- type ServerAuthConfig
- type SubmitTokenRequest
- type Workspace
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultClientID ¶
func DefaultClientID() string
DefaultClientID returns the OpenAI PKCE client ID.
Types ¶
type AuthDeps ¶
type AuthDeps interface {
GeneratePKCE() (verifier, challenge string, err error)
RequestDeviceCode(backendURL, codeVerifier string) (*setup.DeviceCode, error)
PollForToken(ctx context.Context, backendURL, deviceCode, codeVerifier string, interval int) (*setup.TokenResponse, error)
OpenBrowser(url string) error
SaveCredentials(creds map[string]any) error
// PrintLoginPrompt displays the device auth URL and code to the user.
// Implementations may suppress output (e.g., headless mode emits NDJSON instead).
PrintLoginPrompt(uri, code string)
}
AuthDeps abstracts external authentication operations for testability.
type AuthResult ¶
AuthResult holds the result of a device code authentication flow.
func AuthenticateServer ¶
func AuthenticateServer(ctx context.Context, cfg ServerAuthConfig, deps AuthDeps) (*AuthResult, error)
AuthenticateServer runs the device code auth flow against the Autopus backend. If deps is nil, real setup package implementations are used.
type CallbackRequest ¶
type CallbackRequest struct {
Code string
Verifier string
RedirectURI string
ClientID string
TokenURL string
}
CallbackRequest represents the data needed to exchange an authorization code.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client communicates with the Autopus backend API.
func (*Client) ListWorkspaces ¶
ListWorkspaces retrieves the user's workspace list from the Autopus backend.
func (*Client) SubmitToken ¶
func (c *Client) SubmitToken(ctx context.Context, req SubmitTokenRequest) error
SubmitToken sends the provider OAuth token to the Autopus backend callback endpoint.
func (*Client) WithServerURL ¶
WithServerURL sets the server URL on the client and returns it for chaining.
type DeviceCodeResponse ¶
type DeviceCodeResponse struct {
DeviceCode string `json:"device_code"`
UserCode string `json:"user_code"`
VerificationURI string `json:"verification_uri"`
ExpiresIn int `json:"expires_in"`
Interval int `json:"interval"` // polling interval in seconds
}
DeviceCodeResponse holds the server's response to a device code request. The server proxies device code creation for OpenAI OAuth on behalf of the CLI.
func RequestOpenAIDeviceCode ¶
func RequestOpenAIDeviceCode(ctx context.Context, serverURL, authToken, workspaceID string) (*DeviceCodeResponse, error)
RequestOpenAIDeviceCode calls the server endpoint to get a device code for OpenAI OAuth. POST {serverURL}/api/v1/workspaces/{workspaceID}/ai-oauth/device-code
type DeviceTokenResponse ¶
type DeviceTokenResponse struct {
Status string `json:"status"` // "pending", "completed", "expired"
AccessToken string `json:"access_token,omitempty"`
RefreshToken string `json:"refresh_token,omitempty"`
ExpiresIn int `json:"expires_in,omitempty"`
}
DeviceTokenResponse is the result of polling the device-token endpoint.
func PollOpenAIDeviceToken ¶
func PollOpenAIDeviceToken(ctx context.Context, serverURL, authToken, workspaceID, deviceCode string, interval int) (*DeviceTokenResponse, error)
PollOpenAIDeviceToken polls the server until OpenAI OAuth completes or the context is cancelled. POST {serverURL}/api/v1/workspaces/{workspaceID}/ai-oauth/device-token
type HeadlessEvent ¶
type HeadlessEvent struct {
SchemaVersion string `json:"schema_version"`
Command string `json:"command"`
GeneratedAt time.Time `json:"generated_at"`
Step string `json:"step"` // "server_auth", "workspace", "openai_oauth", "complete"
Action string `json:"action,omitempty"` // "login_required" when user action is needed
Status string `json:"status,omitempty"` // "success", "error"
URL string `json:"url,omitempty"` // verification URL
Code string `json:"code,omitempty"` // user code
ExpiresIn int `json:"expires_in,omitempty"` // seconds until expiration
WorkspaceID string `json:"workspace_id,omitempty"` // workspace identifier
WorkspaceName string `json:"workspace_name,omitempty"` // workspace display name
Provider string `json:"provider,omitempty"` // "openai"
Error string `json:"error,omitempty"` // error message on failure
}
HeadlessEvent is a single NDJSON line written to stdout in headless mode.
type OAuthConfig ¶
type OAuthConfig struct {
ClientID string
Scopes string
AuthURL string
TokenURL string
Port int // Callback port. 0 = use default (1455).
}
OAuthConfig holds configuration for the OpenAI OAuth flow.
type OAuthFlowResult ¶
type OAuthFlowResult struct {
Verifier string
Challenge string
State string
Port int
RedirectURI string
}
OAuthFlowResult contains the PKCE pair and local server info from StartOAuthFlow.
func StartOAuthFlow ¶
func StartOAuthFlow(ctx context.Context, cfg OAuthConfig) (*OAuthFlowResult, error)
StartOAuthFlow generates PKCE credentials and starts a local callback server. It does NOT open the browser or wait for callback — use WaitForCallback for that.
type OAuthResult ¶
type OAuthResult struct {
AccessToken string `json:"access_token"`
RefreshToken string `json:"refresh_token"`
ExpiresIn int `json:"expires_in"`
ExpiresAt time.Time
Scopes string `json:"scope"`
}
OAuthResult holds tokens returned from the token exchange.
func ExchangeAuthCode ¶
func ExchangeAuthCode(ctx context.Context, req CallbackRequest) (*OAuthResult, error)
@AX:NOTE [AUTO] @AX:REASON: public API — fan_in < 3, downgraded from ANCHOR during sync ExchangeAuthCode exchanges an authorization code for tokens.
func WaitForCallback ¶
func WaitForCallback(ctx context.Context, cfg OAuthConfig) (*OAuthResult, error)
WaitForCallback starts a local HTTP server and waits for the OAuth callback. It respects the provided context for cancellation/timeout.
type ServerAuthConfig ¶
type ServerAuthConfig struct {
ServerURL string
}
ServerAuthConfig holds configuration for server authentication.
type SubmitTokenRequest ¶
type SubmitTokenRequest struct {
ProviderToken string `json:"provider_token"`
RefreshToken string `json:"refresh_token,omitempty"`
WorkspaceID string `json:"workspace_id"`
Provider string `json:"provider"`
}
SubmitTokenRequest holds the data needed to submit a provider token to the server.