Documentation
¶
Overview ¶
Package desktopmode lets the desktop app trade a per-install token for a dashboard session over authenticated loopback, and pins Host and Origin.
Index ¶
Constants ¶
const ( ExchangePath = "/api/desktop/exchange" RotatePath = "/api/desktop/rotate" RevokePath = "/api/desktop/revoke" )
Route paths served by Wrap. They sit outside the API router's route table.
const Host = "levelrail.localhost"
Host is the only name desktop mode answers to. Browsers share cookies across ports of one host name, so a name of its own keeps the session away from other local servers.
Variables ¶
var ErrNotSingleUser = errors.New("desktopmode: install is not single-user")
ErrNotSingleUser means the install has several users, which desktop mode does not support.
Functions ¶
func AllowedHosts ¶
AllowedHosts expands Host over the given ports into the exact Host header values allowed.
Types ¶
type Config ¶
type Config struct {
Tokens *Tokens
Sessions Sessions
// Admin returns the root admin of this single-user install.
Admin func(ctx context.Context) (authengine.LegacyUser, error)
// TTL is read per exchange so the runtime setting applies live.
TTL func(ctx context.Context) time.Duration
// Audit records one row; it must never receive secret values.
Audit func(ctx context.Context, e store.AuditEntry)
Logger *slog.Logger
// Ports are the dashboard ports (guest and host side) the Host header may carry.
Ports []string
// FailuresPerMin bad tokens from one peer start a block of Block; 0 disables the limit.
FailuresPerMin int
Block time.Duration
Now func() time.Time
// AllowRemotePeer lifts the loopback peer requirement; tests only.
AllowRemotePeer bool
}
Config wires a Service. Zero limits disable the matching guard.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is desktop mode: token exchange plus Host and Origin enforcement.
type Sessions ¶
type Sessions interface {
IssueSessionTTL(ctx context.Context, u authengine.LegacyUser, userAgent, ip string, ttl time.Duration) (string, error)
Revoke(ctx context.Context, token string)
RevokeAll(ctx context.Context, legacyUserID string) error
}
Sessions is the slice of the auth library desktop mode needs.
type Tokens ¶
type Tokens struct {
// contains filtered or unexported fields
}
Tokens owns the per-install token. Only its hash stays in memory and in the hash file; the plaintext lives in the handoff file for the host app.
func NewTokens ¶
NewTokens loads the stored hash, or creates a token on first use. A handoff file that is missing, not a plain 0600 file, or not matching the hash (a crash between the two writes) mints a fresh token, since the host could not use the old one.
func (*Tokens) Revoke ¶
Revoke deletes the token and its hash. It lasts until the next boot, which creates a fresh token like a first run; to keep desktop mode closed, turn APP_DESKTOP_MODE off.