Wires the web layer end to end: server-side sessions, CSRF protection, a JSON login/logout pair, remember-me, CORS, and the security-headers/anonymous middlewares — all behind one middleware.Chain. Everything is in-memory; there is no database or external dependency to stand up.

Running it

The remember-me HMAC key must come from the environment — the example fails fast (log.Fatal) if REMEMBER_ME_KEY is unset or shorter than 32 bytes, since a committed key would let anyone with repo access forge remember-me tokens.

The chain, top to bottom

The /login and /logout endpoints are mounted on a mux that the chain wraps.

Key configuration

Users, encoder, manager

Session store

Remember-me

The fetcher returns a fragment of the user’s stored password hash, so a password change invalidates outstanding remember-me tokens automatically — no separate revocation list to maintain:

CSRF (session-backed synchronizer token)

CORS

The one chain that wraps everything

sessionResolver is a small example middleware, not a library type: it reads the SESSION cookie, loads the session, and reloads the user’s authorities from the UserService on every request — so a revoked role or a disabled/ locked account takes effect immediately rather than being frozen at login time.

Trying it out

The running process listens on plain http://localhost:8080 (see http.ListenAndServe(":8080", handler) in main); the package doc comment’s https://localhost:8443 curl example describes a real TLS-terminated deployment, not this exact process. /me has no authz route rule guarding it, so it is reachable unauthenticated — core.MustAuthentication never panics because Anonymous() always puts some authentication (anonymous or real) on the context: