@@ -43,18 +43,30 @@ func NewHandler(cfg *config.Config, o *OIDC, users *user.Store, sessions *sessio
4343 return & Handler {Cfg : cfg , OIDC : o , Users : users , Sessions : sessions }
4444}
4545
46- // Register wires the three /auth/* routes onto the supplied mux. The
47- // already-signed-in check at GET /{$} is owned by internal/web (U7) —
48- // keeping the root route there lets the web layer own asset serving and
49- // the session-redirect compose cleanly without circular imports.
50- //
51- // The proxy host routing (U8) will eventually differentiate auth-host
52- // paths from upstream-app paths, but for U6 every route serves regardless
53- // of host — the binary listens on a single port and the mux dispatches
54- // by path.
55- func (h * Handler ) Register (mux * http.ServeMux ) {
56- mux .HandleFunc ("GET /auth/login" , h .HandleLogin )
57- mux .HandleFunc ("GET /auth/callback" , h .HandleCallback )
46+ // MountOptions configures per-route middleware applied by Mount. A nil
47+ // limiter skips rate limiting for that route — fine in tests, never in
48+ // production (main.go must always pass real limiters).
49+ type MountOptions struct {
50+ LoginLimiter * httplog.RateLimiter
51+ CallbackLimiter * httplog.RateLimiter
52+ }
53+
54+ // Mount wires every /auth/* route onto mux. This is the single source
55+ // of truth for auth-route registration — both production (cmd/forge-proxy)
56+ // and tests call it. Adding a new route here means it appears in both
57+ // the running binary and the test fixture, which prevents the
58+ // "registered in tests, 404s in prod" trap.
59+ func (h * Handler ) Mount (mux * http.ServeMux , opts MountOptions ) {
60+ var login http.Handler = http .HandlerFunc (h .HandleLogin )
61+ if opts .LoginLimiter != nil {
62+ login = httplog .RateLimitMiddleware (opts .LoginLimiter , login )
63+ }
64+ var callback http.Handler = http .HandlerFunc (h .HandleCallback )
65+ if opts .CallbackLimiter != nil {
66+ callback = httplog .RateLimitMiddleware (opts .CallbackLimiter , callback )
67+ }
68+ mux .Handle ("GET /auth/login" , login )
69+ mux .Handle ("GET /auth/callback" , callback )
5870 mux .HandleFunc ("POST /auth/logout" , h .HandleLogout )
5971 mux .HandleFunc ("GET /auth/me" , h .HandleMe )
6072}
0 commit comments