Documentation
¶
Overview ¶
Package session implements opaque, purpose-bound, hashed browser sessions. It is storage-agnostic: applications implement Store using their own database.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("session not found")
ErrNotFound indicates an absent or invalidated session.
Functions ¶
Types ¶
type Authenticator ¶
type Authenticator[User any] struct { // Manager provides secure session lookup. Manager Manager[User] // CookieName is the cookie carrying the opaque session token. CookieName string }
Authenticator resolves users from a named session cookie.
func (Authenticator[User]) Authenticate ¶
func (a Authenticator[User]) Authenticate(request *http.Request) (User, error)
Authenticate implements the shared auth.Authenticator contract.
type CookieConfig ¶
type CookieConfig struct {
// Name is the session cookie name, unique within the deployment.
Name string
// Path is the cookie path, typically the mounted application prefix or root.
Path string
// Lifetime is the browser cookie lifetime.
Lifetime time.Duration
// Secure must be true for HTTPS deployments.
Secure bool
// SameSite is the cookie cross-site policy.
SameSite http.SameSite
}
CookieConfig defines an HTTP-only cookie scoped to the application's deployment path.
type Manager ¶
type Manager[User any] struct { // Store is the application-supplied durable session store. Store Store[User] // Lifetime is the maximum age of newly issued sessions. Lifetime time.Duration // Purpose isolates hashes from other types of token. Purpose string }
Manager issues, resolves, and revokes sessions for one application.
func (Manager[User]) Resolve ¶
Resolve authenticates the session token using application-owned persistence.
type Store ¶
type Store[User any] interface { // Create atomically persists a session hash and its expiry. Create(context.Context, string, User, time.Time) error // Lookup resolves a live session hash to an application user. Lookup(context.Context, string) (User, error) // Revoke permanently invalidates a session hash. Revoke(context.Context, string) error }
Store persists only hashes of bearer session tokens, never raw tokens. Lookup must exclude expired and revoked sessions and disabled accounts.