From 407966fc9411bb6cdc1bcb2301867bfa3c32004a Mon Sep 17 00:00:00 2001 From: Gabriel20xx Date: Thu, 17 Sep 2026 00:32:46 +0200 Subject: [PATCH] feat: honor project login requirement in CollabTable --- backend/auth.go | 10 ++++------ backend/server.go | 31 ++++++++++++++++--------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/backend/auth.go b/backend/auth.go index 000c1af..b6b1550 100644 --- a/backend/auth.go +++ b/backend/auth.go @@ -69,12 +69,10 @@ const ( legacySessionCookieName = "collabtable_session" ) -// collabTableAuthStore adapts *DB to sharedauth.ProxyStore. CollabTable never -// had an independent "require login" toggle (a session was always required -// whenever AUTHGUARD_URL was configured at all) so LoginRequired always -// reports true and SetLoginRequired is a no-op -- server.go correspondingly -// wires sharedauth.Service.Require rather than the *IfLoginRequired -// middleware family. IsSetupClaimed/TryClaimSetup/UnclaimSetup delegate +// collabTableAuthStore adapts *DB to sharedauth.ProxyStore. The login +// requirement is runtime-controlled by ProjectConfigurator through +// sharedauth.Service's internal endpoint; this store supplies the conservative +// required-by-default fallback. IsSetupClaimed/TryClaimSetup/UnclaimSetup delegate // straight through to *DB's existing methods of the same name/signature (see // db.go), reusing the collabtable_setup_state table/queries verbatim. type collabTableAuthStore struct { diff --git a/backend/server.go b/backend/server.go index 875d906..1da4823 100644 --- a/backend/server.go +++ b/backend/server.go @@ -175,19 +175,20 @@ func (s *Server) registerRoutes(mux *http.ServeMux, webRoot fs.FS) { mux.HandleFunc("GET /api/auth/status", s.auth.Status) mux.HandleFunc("POST /api/auth/setup", s.auth.Signup) mux.HandleFunc("POST /api/auth/login", s.auth.Login) - mux.Handle("POST /api/auth/logout", s.auth.Require(http.HandlerFunc(s.auth.Logout))) - mux.Handle("POST /api/auth/credentials", s.auth.Require(http.HandlerFunc(s.auth.UpdateMe))) - mux.Handle("GET /api/auth/users", s.auth.Require(http.HandlerFunc(s.auth.ManagedUsers))) - mux.Handle("POST /api/auth/users", s.auth.Require(http.HandlerFunc(s.auth.ManagedCreateUser))) - mux.Handle("PUT /api/auth/users/{id}", s.auth.Require(http.HandlerFunc(s.auth.ManagedUpdateUser))) - mux.Handle("PATCH /api/auth/users/{id}", s.auth.Require(http.HandlerFunc(s.auth.ManagedUpdateUser))) - mux.Handle("DELETE /api/auth/users/{id}", s.auth.Require(http.HandlerFunc(s.auth.ManagedDeleteUser))) - mux.Handle("GET /api/auth/totp/status", s.auth.Require(http.HandlerFunc(s.auth.TOTPStatus))) - mux.Handle("POST /api/auth/totp/setup", s.auth.Require(http.HandlerFunc(s.auth.TOTPInitiate))) - mux.Handle("POST /api/auth/totp/enable", s.auth.Require(http.HandlerFunc(s.auth.TOTPVerify))) - mux.Handle("POST /api/auth/totp/disable", s.auth.Require(http.HandlerFunc(s.auth.TOTPDisable))) - mux.Handle("GET /api/auth/token/status", s.auth.Require(http.HandlerFunc(s.handleTokenStatus))) - mux.Handle("POST /api/auth/token/regenerate", s.auth.Require(http.HandlerFunc(s.handleTokenRegenerate))) + mux.Handle("PUT /api/auth/access/internal", s.auth.SetLoginRequiredInternal(s.internalServiceSecret)) + mux.Handle("POST /api/auth/logout", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.Logout))) + mux.Handle("POST /api/auth/credentials", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.UpdateMe))) + mux.Handle("GET /api/auth/users", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.ManagedUsers))) + mux.Handle("POST /api/auth/users", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.ManagedCreateUser))) + mux.Handle("PUT /api/auth/users/{id}", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.ManagedUpdateUser))) + mux.Handle("PATCH /api/auth/users/{id}", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.ManagedUpdateUser))) + mux.Handle("DELETE /api/auth/users/{id}", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.ManagedDeleteUser))) + mux.Handle("GET /api/auth/totp/status", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.TOTPStatus))) + mux.Handle("POST /api/auth/totp/setup", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.TOTPInitiate))) + mux.Handle("POST /api/auth/totp/enable", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.TOTPVerify))) + mux.Handle("POST /api/auth/totp/disable", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.auth.TOTPDisable))) + mux.Handle("GET /api/auth/token/status", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.handleTokenStatus))) + mux.Handle("POST /api/auth/token/regenerate", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.handleTokenRegenerate))) // Sync/collaboration API routes use a long-lived bearer token shared by the // user's devices. This is deliberately separate from browser sessions. @@ -217,8 +218,8 @@ func (s *Server) registerRoutes(mux *http.ServeMux, webRoot fs.FS) { // The dashboard is a public SPA shell, but its data and tech-stack endpoints // are protected by the browser session. - mux.Handle("GET /api/tech-stack", s.auth.Require(http.HandlerFunc(s.handleTechStack))) - mux.Handle("GET /web/data", s.auth.Require(http.HandlerFunc(s.handleWebData))) + mux.Handle("GET /api/tech-stack", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.handleTechStack))) + mux.Handle("GET /web/data", s.auth.RequireIfLoginRequired(http.HandlerFunc(s.handleWebData))) mux.Handle("/", spaFileServer(webRoot)) }