Documentation
¶
Overview ¶
Package auth implements the device-flow client and token storage.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDenied = errors.New("device was denied in the browser")
ErrDenied is returned when the user denied the device in the browser.
var ErrExpired = errors.New("code expired, run braid login again")
ErrExpired is returned when the device code expired.
var ErrNoKeychain = errors.New("no OS keychain available")
ErrNoKeychain means the OS keychain backend is unavailable.
var ErrNoToken = errors.New("not logged in")
ErrNoToken means no token is stored for the server.
Functions ¶
func Login ¶
func Login(ctx context.Context, hc *http.Client, serverURL string, info protocol.DeviceCodeRequest, show func(protocol.DeviceCodeResponse), sleep func(context.Context, time.Duration) error) (protocol.TokenResponse, error)
Login runs the device flow: POST code, call show(resp), poll every interval (+5 s on slow_down) until success, access_denied, expired_token or ctx end. Response bodies are never included in errors.
Types ¶
type Store ¶
type Store interface {
Get(server string) (string, error) // ErrNoToken if absent
Set(server, token string) error
Delete(server string) error
Kind() string // "keychain" | "file"
}
Store keeps one device token per server URL.
func NewFile ¶
NewFile stores tokens in <configDir>/token as JSON {server: token} with mode 0600 (dir 0700); refuses to read a file with group/other permission bits (unix).
func NewKeychain ¶
func NewKeychain() Store
NewKeychain uses go-keyring service "braid", user = server URL; Set returns ErrNoKeychain when the backend is unavailable.