Documentation
¶
Overview ¶
Package auth finds, stores and forgets the API token (design §4).
A token comes from QUANTIC_TOKEN, the system keyring, or a file, in that order. Each is kept per Quantic host, so a token for a local Phoenix server never replaces the one for quantic.finance.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not in the keyring")
ErrNotFound is what a Keyring returns when it holds nothing for that service and user. Any other error means the keyring itself failed.
var ErrNotSignedIn = errors.New("not signed in")
ErrNotSignedIn means there is no token for the host anywhere.
Functions ¶
This section is empty.
Types ¶
type Keyring ¶
type Keyring interface {
Get(service, user string) (string, error)
Set(service, user, secret string) error
Delete(service, user string) error
}
Keyring is the part of a system keyring the CLI uses: one secret per service and user. SystemKeyring is the real one; tests use their own.
type Saved ¶
Saved says where Save put a token. KeyringErr is why it isn't in the keyring, when it went to the file instead.
type Secret ¶
type Secret struct {
// contains filtered or unexported fields
}
Secret is a token that can't be printed by accident; only Reveal gives the token, and only the code that sets the Authorization header calls it.
encoding/json, and log/slog's JSON handler, can't see an unexported field, so to them a Secret is {}. fmt can: it reads unexported fields through reflection. What stops it is the pointer below.
func ParseSecret ¶
ParseSecret checks that s looks like a token, after trimming the newline a file or a paste leaves. It never puts s in its error.
type Source ¶
type Source string
Source says where a token came from, for messages and `auth status`.
type Store ¶
type Store struct {
// Env is QUANTIC_TOKEN's value; set, it wins over anything stored.
Env string
Keyring Keyring
// File is where tokens go when the keyring can't take them (design §4):
// $XDG_CONFIG_HOME/quantic/tokens.json, readable only by its owner.
File string
}
Store finds and keeps tokens, one per Quantic host ("quantic.finance", "localhost:4000").
func (*Store) Delete ¶
Delete forgets host's token in the keyring and the file, and returns where it was. QUANTIC_TOKEN is the caller's to unset.
type SystemKeyring ¶
type SystemKeyring struct{}
SystemKeyring is the operating system's keyring: the Secret Service on Linux (GNOME Keyring, KWallet), the Keychain on macOS, the Credential Manager on Windows.
func (SystemKeyring) Delete ¶
func (SystemKeyring) Delete(service, user string) error
func (SystemKeyring) Set ¶
func (SystemKeyring) Set(service, user, secret string) error