pomerium/internal/sessions/store.go

39 lines
1 KiB
Go

// Package sessions handles the storage, management, and validation
// of pomerium user sessions.
package sessions
import (
"context"
"errors"
"net/http"
)
// SessionStore defines an interface for loading, saving, and clearing a session.
type SessionStore interface {
SessionLoader
ClearSession(http.ResponseWriter, *http.Request)
SaveSession(http.ResponseWriter, *http.Request, any) error
}
// SessionLoader defines an interface for loading a session.
type SessionLoader interface {
LoadSession(context.Context, *http.Request) (string, error)
}
type multiSessionLoader []SessionLoader
func (l multiSessionLoader) LoadSession(ctx context.Context, r *http.Request) (string, error) {
for _, ll := range l {
s, err := ll.LoadSession(ctx, r)
if errors.Is(err, ErrNoSessionFound) {
continue
}
return s, err
}
return "", ErrNoSessionFound
}
// MultiSessionLoader returns a session loader that returns the first session available.
func MultiSessionLoader(loaders ...SessionLoader) SessionLoader {
return multiSessionLoader(loaders)
}