Documentation
¶
Overview ¶
Package middleware provides HTTP authentication and session management.
Index ¶
- Constants
- Variables
- func ClearSessionCookie(w http.ResponseWriter)
- func Companies(sessCipher string) (map[string]Entity, error)
- func CompaniesByEmail(email string) map[string]Entity
- func CompanyAllowed(company, email string) (bool, error)
- func GitCredentials() (string, string)
- func HTTPAuth(next http.Handler) http.Handler
- func HTTPLog(next http.Handler) http.Handler
- func Init() error
- func LocalOnly(next http.Handler) http.Handler
- func Login(email, pass string) (string, error)
- type Entities
- type Entity
- type Sess
- type User
Constants ¶
View Source
const ( // SessionMaxAge is the maximum age of a session in seconds (8 hours) SessionMaxAge = 8 * 60 * 60 // IVSize is the size of random bytes to generate (24 bytes = 32 base64 chars) IVSize = 24 )
Variables ¶
View Source
var ( ErrUserNotFound = errors.New("user not found") ErrInvalidPassword = errors.New("invalid password") ErrSessionExpired = errors.New("session expired") ErrUserNoCompany = errors.New("user has no company assigned") ErrInvalidAPIKey = errors.New("invalid API key") )
Sentinel errors for authentication failures.
Functions ¶
func ClearSessionCookie ¶
func ClearSessionCookie(w http.ResponseWriter)
ClearSessionCookie sends an expired cookie to clear the session.
func CompaniesByEmail ¶
CompaniesByEmail returns the companies a user has access to by email.
func CompanyAllowed ¶
CompanyAllowed checks if a user has access to a company.
func GitCredentials ¶
GitCredentials returns configured git user and token
Types ¶
type Entities ¶
type Entities struct {
IV string `json:"-"`
Version int
GitUser string `json:"-"`
GitToken string `json:"-"`
Company map[string]Entity
User []User
}
Entities contains all company and user configuration.
type Entity ¶
type Entity struct {
Years []string
YearRevenue map[string]string // Revenue per year (EUR)
Name string
COC string
VAT string
IBAN string
BIC string
Salt string `json:"-"`
}
Entity represents a company configuration.
type User ¶
type User struct {
Email string
Hash string `json:"-"`
Company []string
Name string
Address1 string
Address2 string
APIKey string `json:"-"` // Optional API key for programmatic access
}
User represents a user with access to companies.
func UserByEmail ¶
UserByEmail finds a user by their email address.
func ValidateAPIKey ¶
ValidateAPIKey validates an API key and returns the associated user. Uses constant-time comparison to prevent timing attacks.
Click to show internal directories.
Click to hide internal directories.