auth

package
v0.1.1-beta.2 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckHandler

func CheckHandler(sm *SessionManager) http.HandlerFunc

CheckHandler returns a handler for GET /api/auth/check.

func LoginHandler

func LoginHandler(ps *PasswordStore, sm *SessionManager, secureCookies bool) http.HandlerFunc

LoginHandler returns a handler for POST /api/auth/login.

func LogoutHandler

func LogoutHandler(sm *SessionManager) http.HandlerFunc

LogoutHandler returns a handler for POST /api/auth/logout.

func Middleware

func Middleware(sm *SessionManager) func(http.Handler) http.Handler

Middleware returns chi-compatible middleware that enforces session auth. Requests arriving over unix sockets bypass auth.

func SetupHandler

func SetupHandler(ps *PasswordStore, sm *SessionManager, secureCookies bool) http.HandlerFunc

SetupHandler returns a handler for POST /api/auth/setup. Sets the initial password. Rejects if a password is already set.

func StatusHandler

func StatusHandler(authEnabled bool, ps *PasswordStore) http.HandlerFunc

StatusHandler returns a handler for GET /api/auth/status. Always public — tells the frontend whether auth is enabled and if setup is needed.

Types

type PasswordStore

type PasswordStore struct {
	// contains filtered or unexported fields
}

PasswordStore manages password hashing and verification with file persistence.

func NewPasswordStore

func NewPasswordStore() (*PasswordStore, error)

NewPasswordStore creates a store backed by ~/.config/guppi/auth.json.

func (*PasswordStore) HasPassword

func (ps *PasswordStore) HasPassword() bool

HasPassword returns true if a password hash is stored.

func (*PasswordStore) SetPassword

func (ps *PasswordStore) SetPassword(password string) error

SetPassword hashes and persists the given password.

func (*PasswordStore) Verify

func (ps *PasswordStore) Verify(password string) bool

Verify checks a password against the stored hash.

type SessionManager

type SessionManager struct {
	// contains filtered or unexported fields
}

SessionManager manages in-memory session tokens with expiry.

func NewSessionManager

func NewSessionManager(ttl time.Duration) *SessionManager

NewSessionManager creates a session manager with the given TTL.

func (*SessionManager) Cleanup

func (sm *SessionManager) Cleanup()

Cleanup removes expired sessions. Call periodically.

func (*SessionManager) Create

func (sm *SessionManager) Create() (string, error)

Create generates a new session token.

func (*SessionManager) Revoke

func (sm *SessionManager) Revoke(token string)

Revoke removes a session token.

func (*SessionManager) Validate

func (sm *SessionManager) Validate(token string) bool

Validate checks if a token is valid and refreshes its expiry (sliding window).

Jump to

Keyboard shortcuts

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