Documentation
¶
Overview ¶
Package sessionauth provides a session-first auth adapter for Vango.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CookiePolicy ¶
type CookiePolicy interface {
ApplyCookiePolicy(r *http.Request, cookie *http.Cookie) (*http.Cookie, error)
}
CookiePolicy applies security defaults to cookies set by the provider.
type Option ¶
type Option func(*Provider)
Option configures a Provider.
func WithCookieName ¶
WithCookieName sets the cookie name used to load session IDs.
func WithCookiePolicy ¶
func WithCookiePolicy(policy CookiePolicy) Option
WithCookiePolicy applies a cookie policy for provider-managed cookies.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider adapts a session store to Vango's auth.Provider interface.
func New ¶
func New(store SessionStore, opts ...Option) *Provider
New creates a session-first auth provider. It panics if store is nil (including typed-nil implementations).
func (*Provider) Middleware ¶
Middleware validates the session cookie and injects the stored session into context.
func (*Provider) Principal ¶
Principal extracts the auth.Principal from a validated request context.
func (*Provider) SetCookiePolicy ¶
func (p *Provider) SetCookiePolicy(policy CookiePolicy)
SetCookiePolicy updates the cookie policy after provider creation.
type SessionStore ¶
type SessionStore interface {
// Get returns a stored session for a session ID.
// Returning (nil, nil) means "not found" and is treated as unauthenticated.
Get(ctx context.Context, sessionID string) (*StoredSession, error)
// Validate checks whether a stored session is currently valid.
// Validate is only called with non-nil session values.
Validate(ctx context.Context, session *StoredSession) error
}
SessionStore is the backing store for session-first auth.
type StoredSession ¶
type StoredSession struct {
ID string
UserID string
Email string
Name string
Roles []string
TenantID string
ExpiresAt time.Time
AuthVersion int
}
StoredSession represents a validated session from a backing store.
func SessionFromContext ¶
func SessionFromContext(ctx context.Context) (*StoredSession, bool)
SessionFromContext returns the stored session from context.