auth

package
v0.7.21 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	SessionCookieName   = "vedetta_session"
	CSRFCookieName      = "vedetta_csrf"
	SessionAbsoluteTTL  = 12 * time.Hour
	SessionIdleTTL      = 30 * time.Minute
	RememberAbsoluteTTL = 30 * 24 * time.Hour // 30 days
	RememberIdleTTL     = 7 * 24 * time.Hour  // 7 days
)
View Source
const (
	AuthKindSession = "session"
	AuthKindToken   = "token"
	AuthKindProxy   = "proxy"
)

Variables

View Source
var (
	ErrInvalidCredentials = errors.New("invalid credentials")
	ErrInsufficientScope  = errors.New("insufficient scope")
	ErrRateLimited        = errors.New("rate limited")
	ErrStorageUnavailable = errors.New("auth storage unavailable")
)

Functions

func IsLoopback

func IsLoopback(addr string) bool

func ValidateConfig

func ValidateConfig(cfg config.AuthConfig) error

Types

type Checker

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

func New

func New(authCfg config.AuthConfig, apiCfg config.APIConfig, db *storage.DB) *Checker

func NewFromDB

func NewFromDB(authCfg config.AuthConfig, apiCfg config.APIConfig, db *storage.DB) *Checker

NewFromDB creates a Checker that reads users from the database rather than from static config. It loads users immediately and supports reloading via reloadUsers.

func (*Checker) Authenticate

func (c *Checker) Authenticate(r *http.Request) (*Principal, error)

func (*Checker) ChangePassword

func (c *Checker) ChangePassword(username, currentPassword, newPassword string) error

ChangePassword verifies the current password and updates to the new one.

func (*Checker) Check

func (c *Checker) Check(user, pass, remoteIP string) bool

func (*Checker) ClearSessionCookies

func (c *Checker) ClearSessionCookies(w http.ResponseWriter, r *http.Request)

func (*Checker) ClientIP

func (c *Checker) ClientIP(r *http.Request) string

func (*Checker) Close

func (c *Checker) Close()

func (*Checker) CreateToken

func (c *Checker) CreateToken(username, name string, scopes []string, remoteIP string) (*storage.APIToken, string, error)

func (*Checker) CreateTokenForPrincipal

func (c *Checker) CreateTokenForPrincipal(principal *Principal, name string, scopes []string, remoteIP string) (*storage.APIToken, string, error)

func (*Checker) Enabled

func (c *Checker) Enabled() bool

Enabled reports whether authentication is active. A nil Checker means no auth users were configured, so the API and RTSP republish are open. This matches the gate used by the RTSP republish server (auth == nil => open).

func (*Checker) Login

func (c *Checker) Login(user, pass, remoteIP, userAgent string, remember bool) (*storage.AuthSession, error)

func (*Checker) Logout

func (c *Checker) Logout(sessionID, username string) error

func (*Checker) ProxyAuthEnabled

func (c *Checker) ProxyAuthEnabled() bool

ProxyAuthEnabled reports whether proxy authentication is configured.

func (*Checker) RequestIsSecure

func (c *Checker) RequestIsSecure(r *http.Request) bool

func (*Checker) RequireCSRF

func (c *Checker) RequireCSRF(r *http.Request, p *Principal) bool

func (*Checker) RevokeToken

func (c *Checker) RevokeToken(id int64, username string) error

func (*Checker) SetSessionCookies

func (c *Checker) SetSessionCookies(w http.ResponseWriter, r *http.Request, session *storage.AuthSession)

func (*Checker) TransportIsSecure

func (c *Checker) TransportIsSecure(r *http.Request) bool

TransportIsSecure reports whether the client's connection actually arrived over HTTPS - either direct TLS or HTTPS forwarded by a trusted proxy. Unlike RequestIsSecure it ignores the exposure policy, so it stays false for plain-HTTP LAN requests. It is the correct gate for transport-only decisions such as emitting HSTS, which must never pin an HTTP-only host to TLS.

func (*Checker) UpdatePassword

func (c *Checker) UpdatePassword(username string, hash []byte)

UpdatePassword updates the in-memory password hash for a user.

type Principal

type Principal struct {
	Username  string    `json:"username"`
	Kind      string    `json:"kind"`
	Scopes    []string  `json:"scopes,omitempty"`
	ExpiresAt time.Time `json:"expires_at,omitempty"`
	SessionID string    `json:"-"`
	CSRFToken string    `json:"-"`
	TokenID   int64     `json:"-"`
}

func (*Principal) Allows

func (p *Principal) Allows(method, path string) bool

func (*Principal) HasAnyScope

func (p *Principal) HasAnyScope(scopes ...string) bool

Jump to

Keyboard shortcuts

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