auth

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package auth provides authentication primitives for the DirIO admin console. It defines the AdminAuth interface (satisfied by an adapter in the server wiring) and the Session type for HMAC-signed, cookie-based login sessions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AdminAuth

type AdminAuth interface {
	AuthenticateAdmin(ctx context.Context, accessKey, secretKey string) bool
}

AdminAuth validates that a given access-key/secret-key pair belongs to an admin user. The implementation lives in the server wiring layer and wraps internal/http/auth.Authenticator so this package stays free of internal/ imports.

type FlashData

type FlashData struct {
	Message string `json:"msg"`
	Type    string `json:"type"`
}

FlashData is the data stored in the flash cookie.

type Session

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

Session manages HMAC-SHA256 signed console session cookies. The signing key is randomly generated at startup, so sessions are invalidated when the server restarts — acceptable for an admin console.

func NewSession

func NewSession() (*Session, error)

NewSession creates a Session with a randomly generated signing key.

func (*Session) Clear

func (s *Session) Clear(w http.ResponseWriter)

Clear deletes the session cookie.

func (*Session) Create

func (s *Session) Create(w http.ResponseWriter, accessKey string) error

Create writes a signed session cookie for the given access key.

func (*Session) GetFlash

func (s *Session) GetFlash(w http.ResponseWriter, r *http.Request) (FlashData, bool)

GetFlash reads, verifies, and clears the flash cookie.

func (*Session) SetFlash

func (s *Session) SetFlash(w http.ResponseWriter, message, msgType string)

SetFlash sets a signed flash cookie with the given message and type.

func (*Session) Validate

func (s *Session) Validate(r *http.Request) (accessKey string, ok bool)

Validate reads and verifies the session cookie. Returns the access key and true if the session is valid and unexpired.

Jump to

Keyboard shortcuts

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