oficina / home Public

Directory: mount the fresh-only handoff consumer at /auth/fresh/start

Bumps the root module's handoff pin to main 69ea999 (ConsumerConfig.StartPath)
and mounts a second handoff.Consumer on the directory's one Store: same
consumer ID, Callback and Finish, RequireFreshAuth, its own start path.
team-provisioning-amendment.md §4 (the directory confirm page) needs it.

TestDirectoryOrdinaryAndFreshStartPaths: /auth/start asks /authorize with no
max_age, /auth/fresh/start with max_age=300.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 463ac45ce9c991b748f80843a1b7f77297238d23 parent 69ea999
6 files changed, +77 −6
  • go.mod +1 −1
  • go.sum +2 −2
  • internal/home/app.go +1 −0
  • internal/home/directory.go +27 −3
  • internal/home/fresh_start_test.go +44 −0
  • internal/home/handoff_failure.go +2 −0
diff --git a/go.mod b/go.mod
index 73e8581..a377be6 100644
--- a/go.mod
+++ b/go.mod
@@ -7,7 +7,7 @@ toolchain go1.26.5
require (
amadan.net/oficina/estilo.git v0.0.0-20261025200559-260f98c42e2d
amadan.net/oficina/home/dashboard v0.0.0-20261024234842-3774eb68f816
- amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489
+ amadan.net/oficina/home/handoff v0.0.0-20261027235000-69ea999ccbf7
amadan.net/oficina/home/roster v0.0.0-20260908123429-74dda570e0cf
amadan.net/rastrillo/rastrillo v0.26.1-0.20260908075707-29e4491631bd
filippo.io/age v1.3.2
diff --git a/go.sum b/go.sum
index 3904a7c..273bb1f 100644
--- a/go.sum
+++ b/go.sum
@@ -4,8 +4,8 @@ amadan.net/oficina/estilo.git v0.0.0-20261025200559-260f98c42e2d h1:p9+01xRdBD7s
amadan.net/oficina/estilo.git v0.0.0-20261025200559-260f98c42e2d/go.mod h1:4u0jNBtIdMLOsJyrScfqoEuYDJF7BBM3qM9YWbzt6aw=
amadan.net/oficina/home/dashboard v0.0.0-20261024234842-3774eb68f816 h1:AFDuOio0MxNxN9ZWVc3lul1QHkNjNUCO56kXpe/Fw3I=
amadan.net/oficina/home/dashboard v0.0.0-20261024234842-3774eb68f816/go.mod h1:+7xsX+QyVFrKy5gDAGh+FZ5+75z4CibWTL0wl9DWAw0=
-amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489 h1:RPKtyry/71i06o8L+gjAaUyexbmG56kO1YPs601URAM=
-amadan.net/oficina/home/handoff v0.0.0-20260908102137-481d2d57f489/go.mod h1:YISpzFJ+iMgrM0rUL032OSzsAQbP4/nozvXLCCOcn1k=
+amadan.net/oficina/home/handoff v0.0.0-20261027235000-69ea999ccbf7 h1:F0wJpR9hBz5CBfCdw80TuBu0Ufioh+tmpODB9Y7ifH0=
+amadan.net/oficina/home/handoff v0.0.0-20261027235000-69ea999ccbf7/go.mod h1:YISpzFJ+iMgrM0rUL032OSzsAQbP4/nozvXLCCOcn1k=
amadan.net/oficina/home/roster v0.0.0-20260908123429-74dda570e0cf h1:SRKjCUgtk42WwR7VSn+V0eLNk20mfiY8dQmzdw13Sbo=
amadan.net/oficina/home/roster v0.0.0-20260908123429-74dda570e0cf/go.mod h1:gqshuXyDtFZUCYbhuZyV3Epc51pUcsLbpqAqiA5UiXg=
amadan.net/rastrillo/rastrillo v0.26.1-0.20260908075707-29e4491631bd h1:jlFSt95M1ontOg+VePU+kIJpChtWqDQAbnmlxqCnbgc=
diff --git a/internal/home/app.go b/internal/home/app.go
index fe40da7..08a5f3b 100644
--- a/internal/home/app.go
+++ b/internal/home/app.go
@@ -42,6 +42,7 @@ type App struct {
runtime *Runtime
directory *directoryFeatures
consumer *handoff.Consumer
+ fresh *handoff.Consumer
origins Origins
credentialHost string
directoryHost string
diff --git a/internal/home/directory.go b/internal/home/directory.go
index 8be4069..34d17c7 100644
--- a/internal/home/directory.go
+++ b/internal/home/directory.go
@@ -17,6 +17,10 @@ import (
"github.com/go-chi/chi/v5"
)
+// freshStartPath is the directory's fresh-only start (handoff
+// ConsumerConfig.StartPath). It asks the credential origin for max_age=300.
+const freshStartPath = "/auth/fresh/start"
+
func newDirectory(cfg Runtime, d *db.DB, logger *slog.Logger) (*App, error) {
if !cfg.validAppPreviews() || cfg.role != "directory" || cfg.origins.validate() != nil || cfg.secrets.Sealer == nil || d == nil || cfg.signer != nil || !cfg.roster.valid(cfg.role, cfg.keys) {
return nil, errExchangeConfig
@@ -40,15 +44,34 @@ func newDirectory(cfg Runtime, d *db.DB, logger *slog.Logger) (*App, error) {
return nil, err
}
a := &App{runtime: &cfg, origins: cfg.origins, credentialHost: strings.TrimPrefix(cfg.origins.Credential, "https://"), directoryHost: strings.TrimPrefix(cfg.origins.Directory, "https://"), secrets: cfg.secrets, db: d, logger: logger, renderer: renderer, sessions: sess}
+ // One completion for both consumers: the directory's one session boundary.
+ complete := func(w http.ResponseWriter, r *http.Request, c assertion.Claims) error {
+ return a.sessions.SignIn(w, r, sessions.Session{Subject: c.Subject, Method: "assertion", AuthTime: time.Unix(c.AuthTime, 0)})
+ }
a.consumer, err = handoff.NewConsumer(handoff.ConsumerConfig{Store: store, ConsumerID: "directory", CurrentSubject: func(r *http.Request) string {
s, ok := sessions.Current(r)
if !ok {
return ""
}
return s.Subject
- }, Complete: func(w http.ResponseWriter, r *http.Request, c assertion.Claims) error {
- return a.sessions.SignIn(w, r, sessions.Session{Subject: c.Subject, Method: "assertion", AuthTime: time.Unix(c.AuthTime, 0)})
- }, Fail: func(w http.ResponseWriter, r *http.Request, status int) {
+ }, Complete: complete, Fail: func(w http.ResponseWriter, r *http.Request, status int) {
+ a.failDirectoryHandoff(w, r, status)
+ }})
+ if err != nil {
+ return nil, err
+ }
+ // The fresh-only consumer (team-provisioning-amendment.md §4, the
+ // directory confirm page; team-members.md §2): the same Store, consumer ID,
+ // Callback and Finish as the ordinary one, its own start path, and
+ // max_age=300 on every authorize it asks for. Store.Finish enforces the
+ // freshness the pending row was started with, whichever Finish serves it.
+ a.fresh, err = handoff.NewConsumer(handoff.ConsumerConfig{Store: store, ConsumerID: "directory", RequireFreshAuth: true, StartPath: freshStartPath, CurrentSubject: func(r *http.Request) string {
+ s, ok := sessions.Current(r)
+ if !ok {
+ return ""
+ }
+ return s.Subject
+ }, Complete: complete, Fail: func(w http.ResponseWriter, r *http.Request, status int) {
a.failDirectoryHandoff(w, r, status)
}})
if err != nil {
@@ -83,6 +106,7 @@ func (a *App) directoryRouter() http.Handler {
r.Post(chooser.choicePath, chooser.Select)
}
r.Get(handoff.StartPath, a.consumer.Start)
+ r.Get(a.fresh.StartPath(), a.fresh.Start)
r.Get(handoff.FinishPath, a.consumer.Finish)
r.Get("/signin", func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, handoff.StartPath, http.StatusSeeOther)
diff --git a/internal/home/fresh_start_test.go b/internal/home/fresh_start_test.go
new file mode 100644
index 0000000..005d3ee
--- /dev/null
+++ b/internal/home/fresh_start_test.go
@@ -0,0 +1,44 @@
+package home
+
+import (
+ "net/url"
+ "strings"
+ "testing"
+
+ "amadan.net/oficina/home/handoff"
+)
+
+// The directory mounts two consumers on one Store: the ordinary start asks
+// the credential origin for an assertion with no age bound, and the fresh
+// start (team-provisioning-amendment.md §4) asks for max_age=300.
+func TestDirectoryOrdinaryAndFreshStartPaths(t *testing.T) {
+ p := newExchangePair(t)
+ for _, c := range []struct {
+ path string
+ maxAge bool
+ }{{handoff.StartPath, false}, {freshStartPath, true}} {
+ r := exchangeRequest(p.directory, "GET", directoryOrigin+c.path+"?return_to=%2Foperator%2Fconfirm", "", nil)
+ if r.Code != 303 {
+ t.Fatal(c.path, r.Code)
+ }
+ u, err := url.Parse(r.Header().Get("Location"))
+ if err != nil || u.Scheme+"://"+u.Host != Origin || u.Path != "/authorize" {
+ t.Fatal(c.path, "redirected elsewhere", r.Header().Get("Location"))
+ }
+ q := u.Query()
+ if q.Get("consumer") != "directory" || !handoff.ValidNonce(q.Get("nonce")) {
+ t.Fatal(c.path, "authorize query", u.RawQuery)
+ }
+ if got := q["max_age"]; c.maxAge != (len(got) == 1 && got[0] == "300") || (!c.maxAge && len(got) != 0) {
+ t.Fatal(c.path, "max_age", got)
+ }
+ namedCookie(t, r, "__Host-oficina-assertion-pending")
+ }
+ // The fresh start answers only its own path; a typo is an ordinary 404.
+ if r := exchangeRequest(p.directory, "GET", directoryOrigin+"/auth/fresh/start/", "", nil); r.Code != 404 {
+ t.Fatal("near-miss fresh path served", r.Code)
+ }
+ if !strings.HasPrefix(freshStartPath, "/auth/") || p.directory.fresh.StartPath() != freshStartPath {
+ t.Fatal("fresh consumer mounted at an unexpected path")
+ }
+}
diff --git a/internal/home/handoff_failure.go b/internal/home/handoff_failure.go
index 1aa45da..cb12d38 100644
--- a/internal/home/handoff_failure.go
+++ b/internal/home/handoff_failure.go
@@ -58,6 +58,8 @@ func (a *App) failDirectoryHandoff(w http.ResponseWriter, r *http.Request, statu
switch r.URL.Path {
case handoff.StartPath:
stage = "directory_start"
+ case freshStartPath:
+ stage = "directory_fresh_start"
case handoff.CallbackPath:
stage = "directory_callback"
case handoff.FinishPath: