auth

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 14 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Service

type Service struct {
	API *api.Client
}

Service provides authentication operations. It wires together the API client, crypto, config, and keyring packages.

func NewService

func NewService(apiClient *api.Client) *Service

NewService creates a new auth service with the given API client.

func (*Service) EnsureAuth

func (s *Service) EnsureAuth(cmd *cobra.Command, args []string) error

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) Logout

func (s *Service) Logout() error

Logout clears all stored credentials and invalidates the server session.

func (*Service) PerformLogin

func (s *Service) PerformLogin(email, password string, privateKey, publicKey []byte) error

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:

  1. Call API login → get tokens + encrypted keys + workspaces
  2. If no keypair: derive key from password → decrypt private key
  3. Store email + tokens + keypair
  4. Decrypt all workspace keys → cache in config
  5. Set personal workspace as default

func (*Service) RefreshSession

func (s *Service) RefreshSession(refreshToken string) error

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:

  1. Generate keypair + encrypt private key (crypto.SetupUser)
  2. Send registration to API
  3. Auto-login with PerformLogin (passing the keypair to skip decryption)

type SignupRequest

type SignupRequest struct {
	FirstName string
	LastName  string
	Email     string
	Password  string
}

SignupRequest contains the information needed to create a new account.

Jump to

Keyboard shortcuts

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