liteauth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Overview

Package liteauth is the single source of truth for Tollecode Lite's local 2FA. It backs BOTH the desktop app (via the stdio command bus) and web mode (via /ws/cmd): because the same sidecar process and the same on-disk store (~/.tollecode/lite-auth.json) serve both, a user registers their authenticator once and can unlock either surface with the same 6-digit code.

The scheme is standard TOTP (RFC 6238): SHA1, 6 digits, 30-second period — compatible with Google Authenticator, 1Password, Authy, etc. Everything here is stdlib (crypto/hmac, crypto/sha1, encoding/base32, crypto/rand).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BeginLogin

func BeginLogin(email string) (exists bool, name string)

BeginLogin reports whether an account exists for email (case-insensitive).

func Register

func Register(name, email string) (userID int, qrURI string, backupCodes []string, err error)

Register starts registration: it mints a fresh TOTP secret + backup codes for a not-yet-verified pending account and returns the otpauth URI (for the QR) and the plaintext backup codes (shown once). Registration only completes when VerifyRegistration succeeds with a valid code.

func Reset

func Reset() (removed bool, err error)

Reset deletes the entire local auth store (see StorePath): the registered account, its TOTP secret, backup codes, and every live session. The next login starts fresh from registration. removed reports whether a file was actually deleted — false means there was nothing to reset (safe, not an error).

func SignOut

func SignOut(token string)

SignOut invalidates a specific session token (best effort).

func StorePath

func StorePath() string

StorePath returns the absolute path of the local auth store, so callers can show the user exactly which file (under which data dir) they are operating on.

Types

type PublicUser

type PublicUser struct {
	ID    int    `json:"id"`
	Name  string `json:"name"`
	Email string `json:"email"`
}

PublicUser is the account shape returned to the frontend (never the secret).

func LocalUser

func LocalUser() *PublicUser

LocalUser returns the registered account (without secrets), or nil.

func ValidateSession

func ValidateSession(token string) (bool, *PublicUser)

ValidateSession reports whether token maps to a live (unexpired) session.

func VerifyLogin

func VerifyLogin(email, code string) (token, expiresAt string, user PublicUser, err error)

VerifyLogin checks a TOTP code (or an unused backup code) for the registered account and, on success, returns a session. A consumed backup code is removed.

func VerifyRegistration

func VerifyRegistration(userID int, code string) (token, expiresAt string, user PublicUser, err error)

VerifyRegistration checks the first code against the pending account; on success it promotes pending → active and returns a session.

Jump to

Keyboard shortcuts

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