Documentation
¶
Overview ¶
Package auth stores account metadata and provider tokens, and enforces the account lock (the mailbox a token belongs to must match the one recorded at login).
Layout under the config dir:
config.toml default_account accounts/<alias>/account.json Account metadata accounts/<alias>/<secret> provider token caches (0600)
Index ¶
- func CheckIdentity(a *Account, actual string) error
- func DefaultConfigDir() string
- func ValidateAlias(alias string) error
- type Account
- type Config
- type Servers
- type Store
- func (s *Store) AccountDir(alias string) string
- func (s *Store) DeleteAccount(alias string) error
- func (s *Store) ListAccounts() ([]Account, error)
- func (s *Store) LoadAccount(alias string) (*Account, error)
- func (s *Store) LoadConfig() (*Config, error)
- func (s *Store) Lock(ctx context.Context, alias string) (func(), error)
- func (s *Store) ReadSecret(alias, name string) ([]byte, error)
- func (s *Store) ResolveAlias(flag string) (string, error)
- func (s *Store) SaveAccount(a *Account) error
- func (s *Store) SaveConfig(c *Config) error
- func (s *Store) WriteSecret(alias, name string, data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckIdentity ¶
CheckIdentity enforces the account lock.
func DefaultConfigDir ¶
func DefaultConfigDir() string
DefaultConfigDir is $EMAIL_CONFIG_DIR, else $XDG_CONFIG_HOME/email, else ~/.config/email (also on macOS: one layout everywhere).
func ValidateAlias ¶
Types ¶
type Account ¶
type Account struct {
Alias string `json:"alias"`
Provider string `json:"provider"`
Mode policy.Mode `json:"mode"`
Username string `json:"username"` // locked identity (UPN / email)
TenantID string `json:"tenant_id,omitempty"`
ClientID string `json:"client_id,omitempty"`
// HomeAccountID is the provider's stable account id (MSAL home_account_id).
HomeAccountID string `json:"home_account_id,omitempty"`
Scopes []string `json:"scopes,omitempty"`
// Servers are the hosts of an imap account (the password is stored
// separately, never in account.json).
Servers *Servers `json:"servers,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type Servers ¶
type Servers struct {
IMAPHost string `json:"imap_host"`
IMAPPort int `json:"imap_port"`
SMTPHost string `json:"smtp_host,omitempty"`
SMTPPort int `json:"smtp_port,omitempty"`
Preset string `json:"preset,omitempty"` // the --preset (or address) they came from
}
Servers are an imap account's IMAP and SMTP endpoints.
type Store ¶
type Store struct {
Dir string
}
func (*Store) AccountDir ¶
func (*Store) DeleteAccount ¶
func (*Store) ListAccounts ¶
func (*Store) LoadConfig ¶
func (*Store) Lock ¶
Lock takes an exclusive lock on the account's token files, shared with every other `email` process (the watch sidecar and the agent's commands refresh the same tokens). The returned function releases it. The lock is advisory (flock) and is dropped by the kernel if the process dies. Waiting for it ends with ctx.
func (*Store) ReadSecret ¶
ReadSecret returns (nil, nil) when the secret does not exist.
func (*Store) ResolveAlias ¶
ResolveAlias picks the account to use: explicit flag, else $EMAIL_ACCOUNT, else config default_account, else the only account if there is exactly one.