auth

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2026 License: MIT Imports: 11 Imported by: 0

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.

  1. POST to /oauth/device/authorize to start the flow.
  2. Display the user code and verification URI.
  3. Attempt to open the browser automatically.
  4. Poll /oauth/device/token until approval, denial, or expiry.
  5. On success, fetch the LLM key via /api/keys/llm/byor.
  6. 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).

Jump to

Keyboard shortcuts

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