auth

package
v0.3.0-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSessionTTL = 24 * time.Hour

DefaultSessionTTL is the default authenticated session lifetime.

Variables

View Source
var (
	ErrAuthNotInitialized = errors.New("authentication is not initialized")
	ErrAuthAlreadySet     = errors.New("authentication is already initialized")
	ErrInvalidCredentials = errors.New("invalid username or password")
	ErrInvalidSession     = errors.New("invalid or expired session")
	ErrInvalidUsername    = errors.New("invalid username")
	ErrWeakPassword       = errors.New("weak password")
	ErrLoginRateLimited   = errors.New("too many login attempts")
)

Functions

func CredentialPathForConfig

func CredentialPathForConfig(configFile string) string

CredentialPathForConfig returns the auth credential file path next to config.

func RegisterPublicRoutes

func RegisterPublicRoutes(v1 *gin.RouterGroup, deps *ServerDependencies)

func RequireAuthenticated

func RequireAuthenticated(deps *ServerDependencies) gin.HandlerFunc

func SessionPathForConfig

func SessionPathForConfig(configFile string) string

Types

type AuthCredentialsRequest

type AuthCredentialsRequest = contracts.AuthCredentialsRequest

type AuthManager

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

AuthManager manages single-user credentials and in-memory sessions.

func NewAuthManager

func NewAuthManager(configFile string, sessionTTL time.Duration) (*AuthManager, error)

NewAuthManager creates an auth manager and loads credentials from disk if present.

func (*AuthManager) AuthenticateSession

func (m *AuthManager) AuthenticateSession(sessionID string) (string, error)

AuthenticateSession validates a session and returns its username.

func (*AuthManager) IsInitialized

func (m *AuthManager) IsInitialized() bool

IsInitialized reports whether credentials exist.

func (*AuthManager) Login

func (m *AuthManager) Login(username, password string, rememberMe bool) (string, error)

Login validates credentials and returns a new session ID.

func (*AuthManager) Logout

func (m *AuthManager) Logout(sessionID string)

Logout invalidates a session.

func (*AuthManager) SessionTTL

func (m *AuthManager) SessionTTL() time.Duration

SessionTTL returns the configured session lifetime.

func (*AuthManager) Setup

func (m *AuthManager) Setup(username, password string) error

Setup initializes single-user credentials.

func (*AuthManager) Username

func (m *AuthManager) Username() (string, bool)

Username returns the configured username when initialized.

type AuthStatusResponse

type AuthStatusResponse = contracts.AuthStatusResponse

type ErrorResponse

type ErrorResponse = contracts.ErrorResponse

type ServerDependencies

type ServerDependencies = core.ServerDependencies

Jump to

Keyboard shortcuts

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