auth

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckIdentity

func CheckIdentity(a *Account, actual string) error

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

func ValidateAlias(alias string) error

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"`
}

func (*Account) Domain

func (a *Account) Domain() string

Domain is the domain of the locked mailbox address.

type Config

type Config struct {
	DefaultAccount string `toml:"default_account"`
}

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 (s *Store) AccountDir(alias string) string

func (*Store) DeleteAccount

func (s *Store) DeleteAccount(alias string) error

func (*Store) ListAccounts

func (s *Store) ListAccounts() ([]Account, error)

func (*Store) LoadAccount

func (s *Store) LoadAccount(alias string) (*Account, error)

func (*Store) LoadConfig

func (s *Store) LoadConfig() (*Config, error)

func (*Store) Lock

func (s *Store) Lock(ctx context.Context, alias string) (func(), error)

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

func (s *Store) ReadSecret(alias, name string) ([]byte, error)

ReadSecret returns (nil, nil) when the secret does not exist.

func (*Store) ResolveAlias

func (s *Store) ResolveAlias(flag string) (string, error)

ResolveAlias picks the account to use: explicit flag, else $EMAIL_ACCOUNT, else config default_account, else the only account if there is exactly one.

func (*Store) SaveAccount

func (s *Store) SaveAccount(a *Account) error

func (*Store) SaveConfig

func (s *Store) SaveConfig(c *Config) error

func (*Store) WriteSecret

func (s *Store) WriteSecret(alias, name string, data []byte) error

WriteSecret writes a token cache file for the account (0600, atomic).

Directories

Path Synopsis
Package oauthflow runs the browser half of an OAuth 2.0 authorization code + PKCE login for a public client.
Package oauthflow runs the browser half of an OAuth 2.0 authorization code + PKCE login for a public client.

Jump to

Keyboard shortcuts

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