Documentation
¶
Index ¶
- Constants
- Variables
- func IsLoopback(addr string) bool
- func ValidateConfig(cfg config.AuthConfig) error
- type Checker
- func (c *Checker) Authenticate(r *http.Request) (*Principal, error)
- func (c *Checker) ChangePassword(username, currentPassword, newPassword string) error
- func (c *Checker) Check(user, pass, remoteIP string) bool
- func (c *Checker) ClearSessionCookies(w http.ResponseWriter, r *http.Request)
- func (c *Checker) ClientIP(r *http.Request) string
- func (c *Checker) Close()
- func (c *Checker) CreateToken(username, name string, scopes []string, remoteIP string) (*storage.APIToken, string, error)
- func (c *Checker) CreateTokenForPrincipal(principal *Principal, name string, scopes []string, remoteIP string) (*storage.APIToken, string, error)
- func (c *Checker) Enabled() bool
- func (c *Checker) Login(user, pass, remoteIP, userAgent string, remember bool) (*storage.AuthSession, error)
- func (c *Checker) Logout(sessionID, username string) error
- func (c *Checker) ProxyAuthEnabled() bool
- func (c *Checker) RequestIsSecure(r *http.Request) bool
- func (c *Checker) RequireCSRF(r *http.Request, p *Principal) bool
- func (c *Checker) RevokeToken(id int64, username string) error
- func (c *Checker) SetSessionCookies(w http.ResponseWriter, r *http.Request, session *storage.AuthSession)
- func (c *Checker) TransportIsSecure(r *http.Request) bool
- func (c *Checker) UpdatePassword(username string, hash []byte)
- type Principal
Constants ¶
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 )
const ( AuthKindSession = "session" AuthKindToken = "token" AuthKindProxy = "proxy" )
Variables ¶
Functions ¶
func IsLoopback ¶
func ValidateConfig ¶
func ValidateConfig(cfg config.AuthConfig) error
Types ¶
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
func NewFromDB ¶
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) ChangePassword ¶
ChangePassword verifies the current password and updates to the new one.
func (*Checker) ClearSessionCookies ¶
func (c *Checker) ClearSessionCookies(w http.ResponseWriter, r *http.Request)
func (*Checker) CreateToken ¶
func (*Checker) CreateTokenForPrincipal ¶
func (*Checker) Enabled ¶
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) ProxyAuthEnabled ¶
ProxyAuthEnabled reports whether proxy authentication is configured.
func (*Checker) SetSessionCookies ¶
func (c *Checker) SetSessionCookies(w http.ResponseWriter, r *http.Request, session *storage.AuthSession)
func (*Checker) TransportIsSecure ¶
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 ¶
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:"-"`
}