Documentation
¶
Overview ¶
Package auth handles authentication for the MigrAI Code CLI, including OAuth 2.0 Device Authorization Grant (RFC 8628) and credential storage.
Index ¶
Constants ¶
View Source
const ( DefaultServerURL = "https://app.migrai.com.br" DefaultModel = "migrai/claude-sonnet-4.6" )
Constants for the MigrAI authentication system.
Variables ¶
This section is empty.
Functions ¶
func DeleteCredentials ¶
func DeleteCredentials() error
DeleteCredentials removes the credentials file (logout).
func SaveCredentials ¶
func SaveCredentials(creds *Credentials) error
SaveCredentials writes credentials to ~/.migrai-code/credentials.json with mode 0600 so only the current user can read them.
Types ¶
type Credentials ¶
type Credentials struct {
APIKey string `json:"api_key"`
ServerURL string `json:"server_url"`
CreatedAt string `json:"created_at"`
ExpiresAt string `json:"expires_at,omitempty"`
Model string `json:"default_model,omitempty"`
PlatformKey string `json:"platform_key,omitempty"`
}
Credentials holds the authentication state persisted to disk.
func DeviceFlowLogin ¶
func DeviceFlowLogin(serverURL string) (*Credentials, error)
DeviceFlowLogin performs the full OAuth 2.0 Device Authorization Grant flow.
- POST to /oauth/device/authorize to start the flow.
- Display the user code and verification URI.
- Attempt to open the browser automatically.
- Poll /oauth/device/token until approval, denial, or expiry.
- On success, fetch the LLM key via /api/keys/llm/byor.
- Return stored Credentials.
func LoadCredentials ¶
func LoadCredentials() (*Credentials, error)
LoadCredentials reads credentials from ~/.migrai-code/credentials.json. Returns nil, nil when the file does not exist (no credentials stored).
Click to show internal directories.
Click to hide internal directories.