providerauth

package
v0.11.2 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// GithubCopilotClientID is GitHub Copilot's official OAuth App client ID.
	GithubCopilotClientID = "Iv1.b507a08c87ecfe98"
)

GitHub device flow constants.

Variables

This section is empty.

Functions

func DeviceFlow

func DeviceFlow(ctx context.Context) (string, error)

DeviceFlow implements GitHub's device flow for Copilot auth.

func LocalOAuthServerPort

func LocalOAuthServerPort() int

LocalOAuthServerPort returns the port of the most recently started local OAuth callback server. Returns 0 if no OAuth flow has been started.

func OpenBrowserURL

func OpenBrowserURL(rawURL string) error

OpenBrowserURL opens a URL in the default browser.

func PollGitHubDeviceFlow

func PollGitHubDeviceFlow(ctx context.Context, clientID, deviceCode string, interval int) <-chan OAuthResult

PollGitHubDeviceFlow polls for the device flow token until authorized or timeout.

func PromptAPIKey

func PromptAPIKey(providerType string) (string, error)

PromptAPIKey prompts the user for an API key (hidden input).

func PromptBaseURL

func PromptBaseURL(defaultURL string) (string, error)

PromptBaseURL prompts for a base URL with a default value.

func StartAnthropicMaxOAuth

func StartAnthropicMaxOAuth(ctx context.Context) <-chan OAuthResult

StartAnthropicMaxOAuth runs the Max/Pro subscription OAuth PKCE flow. Uses claude.ai as the authorize endpoint; the resulting token is used directly as a Bearer token (no API key creation step). Experimental: may have restrictions.

func StartAnthropicOAuth

func StartAnthropicOAuth(ctx context.Context) <-chan OAuthResult

StartAnthropicOAuth runs the Console OAuth PKCE flow for Anthropic. It uses redirect_uri=https://console.anthropic.com/oauth/code/callback (Anthropic's own callback page) with scopes org:create_api_key user:profile user:inference. Since Anthropic redirects to their own page (not localhost), the CLI opens a local server to accept a manually-pasted code — we keep a localhost callback for a seamless paste-free experience on platforms where it works.

Flow:

  1. Open browser to authorize URL
  2. User authorizes; Anthropic redirects to their callback page showing the code
  3. Our local server also accepts the redirect if the browser follows localhost
  4. On success, exchange code for access token then create a permanent API key

Types

type DeviceCodeResult

type DeviceCodeResult struct {
	DeviceCode      string
	UserCode        string
	VerificationURI string
	ExpiresIn       int
	Interval        int
}

DeviceCodeResult holds the response from a device code request.

func StartGitHubDeviceFlow

func StartGitHubDeviceFlow(ctx context.Context, clientID string) (*DeviceCodeResult, error)

StartGitHubDeviceFlow initiates the GitHub device code flow. Returns the device code result so the TUI can display the user code, then call PollGitHubDeviceFlow to wait for authorization.

type ModelInfo

type ModelInfo struct {
	ID   string
	Name string
}

ModelInfo describes an available model from a provider.

func ListModels

func ListModels(ctx context.Context, providerType, apiKey, baseURL string) ([]ModelInfo, error)

ListModels fetches available models from the given provider type.

type OAuthResult

type OAuthResult struct {
	Token string
	Err   error
}

OAuthResult is returned when a browser-based auth flow completes.

Jump to

Keyboard shortcuts

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