auth

package
v0.1.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidPassword = errors.New("invalid password")
	ErrNoPasswordSet   = errors.New("no password set")
	ErrInvalidToken    = errors.New("invalid token")
)
View Source
var PublicRoutes = []string{
	"/",
	"/auth/login",
	"/auth/status",
	"/health",
	"/health/live",
	"/health/ready",
	"/health/startup",
	"/ready",
	"/metrics",
}

PublicRoutes are routes that don't require authentication

View Source
var StaticPrefixes = []string{
	"/assets/",
	"/static/",
	"/share/",
	"/api/shares/access/",
}

StaticPrefixes are static asset prefixes that don't require authentication

Functions

func GenerateSessionID

func GenerateSessionID() string

GenerateSessionID generates a random session ID

Types

type AuthMiddleware

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

AuthMiddleware handles authentication for protected routes

func NewAuthMiddleware

func NewAuthMiddleware(ps *PasswordService) *AuthMiddleware

NewAuthMiddleware creates a new auth middleware

func (*AuthMiddleware) IsPublicRoute

func (m *AuthMiddleware) IsPublicRoute(path string) bool

IsPublicRoute checks if the given path is a public route

func (*AuthMiddleware) Middleware

func (m *AuthMiddleware) Middleware(next http.Handler) http.Handler

Middleware returns the middleware function for use in the server

func (*AuthMiddleware) RequireAuth

func (m *AuthMiddleware) RequireAuth(next http.Handler) http.Handler

RequireAuth wraps a handler with authentication checking

type Claims

type Claims struct {
	jwt.RegisteredClaims
}

Claims represents JWT claims

type PasswordService

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

PasswordService handles password operations

func NewPasswordService

func NewPasswordService(password string) *PasswordService

NewPasswordService creates a new password service

func (*PasswordService) GenerateToken

func (ps *PasswordService) GenerateToken() (string, error)

GenerateToken creates a new JWT token

func (*PasswordService) IsEnabled

func (ps *PasswordService) IsEnabled() bool

IsEnabled returns whether password authentication is enabled

func (*PasswordService) ValidatePassword

func (ps *PasswordService) ValidatePassword(password string) bool

ValidatePassword checks if the provided password matches the stored hash

func (*PasswordService) ValidateToken

func (ps *PasswordService) ValidateToken(tokenString string) bool

ValidateToken checks if the token is valid

Jump to

Keyboard shortcuts

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