Documentation
¶
Overview ¶
Package auth orchestrates the authentication flows (init, login, logout).
This mirrors the Python SecretsCLI's auth.py module. It coordinates between the API client, crypto, config, and keyring packages to perform the full authentication lifecycle.
The key function is PerformLogin — used by both init (signup) and login flows. It handles: API auth → key decryption → credential storage → workspace caching.
Index ¶
- type Service
- func (s *Service) EnsureAuth(cmd *cobra.Command, args []string) error
- func (s *Service) Logout() error
- func (s *Service) PerformLogin(email, password string, privateKey, publicKey []byte) error
- func (s *Service) RefreshSession(refreshToken string) error
- func (s *Service) Signup(req SignupRequest) error
- type SignupRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Service ¶
Service provides authentication operations. It wires together the API client, crypto, config, and keyring packages.
func NewService ¶
NewService creates a new auth service with the given API client.
func (*Service) EnsureAuth ¶
EnsureAuth is a Cobra PersistentPreRunE middleware that checks session validity. It automatically refreshes the access token if it is expired or close to expiring, assuming a valid refresh token exists.
func (*Service) PerformLogin ¶
PerformLogin completes the login flow: authenticate, decrypt keys, store credentials.
This is the heart of the auth system — used by both signup (via auto-login) and the login command.
Parameters:
- email, password: user credentials
- privateKey, publicKey: if provided (signup flow), skip key decryption. If nil (login flow), decrypt from the API response.
Flow:
- Call API login → get tokens + encrypted keys + workspaces
- If no keypair: derive key from password → decrypt private key
- Store email + tokens + keypair
- Decrypt all workspace keys → cache in config
- Set personal workspace as default
func (*Service) RefreshSession ¶
RefreshSession uses the refresh token to get a new access token.
func (*Service) Signup ¶
func (s *Service) Signup(req SignupRequest) error
Signup creates a new user account and performs auto-login.
Flow:
- Generate keypair + encrypt private key (crypto.SetupUser)
- Send registration to API
- Auto-login with PerformLogin (passing the keypair to skip decryption)