Documentation
¶
Overview ¶
Package session holds secure-mode sessions: the server side of a signed-in browser, its identity refresh, and the /auth/me and /auth/logout routes.
Index ¶
- Constants
- Variables
- func IdentityFrom(ctx context.Context) (oidc.Identity, bool)
- type Info
- type Options
- type Refresher
- type Store
- func (s *Store) Complete(w http.ResponseWriter, r *http.Request, res oidc.Result)
- func (s *Store) Logout(w http.ResponseWriter, r *http.Request)
- func (s *Store) Me(w http.ResponseWriter, r *http.Request)
- func (s *Store) Middleware(next http.Handler) http.Handler
- func (s *Store) Run(ctx context.Context)
- func (s *Store) StillSignedIn(w http.ResponseWriter, r *http.Request) (*http.Request, error)
Constants ¶
const ( DefaultIdle = 30 * time.Minute DefaultAbsolute = 8 * time.Hour DefaultMax = 1000 )
Defaults for Options.
const CookieName = "snellius_session"
CookieName is the session cookie.
Variables ¶
var ErrStale = errors.New("session identity awaits its refresh")
ErrStale is the commit check's answer while the session's identity awaits its refresh.
Functions ¶
Types ¶
type Info ¶
type Info struct {
Identity oidc.Identity
// Issuer and Subject name the person; AuditID is the session's opaque audit ID.
Issuer, Subject, AuditID string
// contains filtered or unexported fields
}
Info is the signed-in identity a request carries.
type Options ¶
type Options struct {
Idle, Absolute time.Duration
Max int
// Clock is nil for the real clock.
Clock clock.WithTicker
// Refresher renews identities; nil ends a session when its identity goes stale.
Refresher Refresher
Audit oidc.Auditor
// Metrics receives the snellius_sessions_active gauge; nil means a private registry.
Metrics *obs.Registry
// CookieSecure marks the session cookie Secure.
CookieSecure bool
// ClientID and RedirectURL build the logout origin check and the RP-initiated logout URL.
ClientID, RedirectURL string
// EndSession returns the issuer's end_session_endpoint, or "" when it has none.
EndSession func() string
// Logger receives refresh failure steps, never a token; nil means slog.Default().
Logger *slog.Logger
}
Options configure a Store. Zero durations and bound take the defaults.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store holds sessions in memory, keyed by a hash of the cookie value.
func (*Store) Complete ¶
Complete starts a session for a sign-in, replacing the browser's previous one or its end notice, then redirects to the return path. It implements oidc.Completer.
func (*Store) Logout ¶
func (s *Store) Logout(w http.ResponseWriter, r *http.Request)
Logout serves POST /auth/logout. The Origin header must be the redirect URL's origin. It deletes the session or its end notice and answers the next URL: the issuer's end-session endpoint without an ID token hint, else "/".
func (*Store) Me ¶
func (s *Store) Me(w http.ResponseWriter, r *http.Request)
Me serves GET /auth/me: the session's username and groups.
func (*Store) Middleware ¶
Middleware lets an /api/ request through only with a fresh session, carrying its identity in the context; others get 401. Other paths pass unchanged.
func (*Store) StillSignedIn ¶
StillSignedIn is the API's commit check for r, a request that passed Middleware. It answers r while the session holds r's identity and that identity is fresh, a request carrying the current identity when a refresh replaced it, and ErrStale while the identity awaits a refresh. When the session ended it writes the 401 a new request with the cookie would get and answers nil. It never refreshes or waits.