feat(auth): method-aware public-route extension point (closes #191) - #193
Merged
Conversation
AuthMiddleware gated every request and offered no supported way for a module to declare anonymous/read-only routes — the only exemption hook was AuthProvider.get_public_paths(), which (a) only the auth provider can contribute to and (b) matches prefix-only, method-agnostic. That blocks modules like gis from exposing a STAC/OGC/TileJSON read API anonymously, and can't isolate `GET .../tilejson` from sibling `PATCH .../visibility` under a shared prefix. Add a first-class extension point: - `simple_module_core.public_routes`: `PublicRoute` (method-aware; prefix/exact/suffix/regex) + `PublicRouteRegistry`. - `ModuleBase.register_public_routes(registry)` lifecycle hook (no-op by default; recognized by the SM007 diagnostic). - Host wires it in `create_app`: aggregates every module's rules plus the `SM_AUTH_PUBLIC_PATHS` host escape hatch, publishes at `app.state.public_routes` (and `app.state.sm.public_routes`). - AuthMiddleware consults the registry method-aware (via `scope["method"]`), in addition to framework defaults and the legacy provider paths (unchanged, back-compat). A GET read route nested under a mutation-bearing prefix can now be exempted without opening the mutations. Docs: docs/framework/public-routes.md.
Deploying simple-module-python with
|
| Latest commit: |
32045fb
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f4461cf6.simple-module-python.pages.dev |
| Branch Preview URL: | https://worktree-fix-auth-public-rou.simple-module-python.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #191. Adds a first-class, method-aware extension point for declaring
anonymous/public routes, so modules (and the host) can expose read-only APIs
(STAC / OGC API / TileJSON, webhooks, status pages) without monkeypatching.
Before this,
AuthMiddlewaregated every request and the only exemption hook wasAuthProvider.get_public_paths()— which only the auth provider couldcontribute to and matched prefix-only, method-agnostically. That blocked
sibling modules from exposing anonymous reads, and couldn't isolate
GET .../tilejsonfrom siblingPATCH .../visibilityunder a shared prefix.What's added
simple_module_core.public_routes:PublicRoute(method-aware; prefix / exact / suffix / regex) +PublicRouteRegistry.ModuleBase.register_public_routes(registry)lifecycle hook (no-op default; recognized by theSM007diagnostic).create_app: aggregates every module's rules plus theSM_AUTH_PUBLIC_PATHShost escape hatch; publishes atapp.state.public_routes(andapp.state.sm.public_routes).AuthMiddlewareconsults the registry method-aware (viascope["method"]), in addition to framework defaults and the legacy provider paths (kept intact — zero breakage forusers/keycloak).docs/framework/public-routes.md.A GET read route nested under a mutation-bearing prefix can now be exempted
without opening the mutations.
Verification
Local CI (fresh): ruff format + check,
ty, file-size cap, hardcoded-strings — all green. 1313 tests passed (incl. a full-stack ASGI test exercisingAuthMiddlewareend-to-end with anonymous + gated requests).Browser QA (
/qa, 9/9 passed, 0 bugs): scoped to the auth-gating surface this change governs./,/users/login,/health→ 200 (anonymous);/dashboard→ 302 → /users/login;/api/users/admin→ 401./zzz-demo-publicviaSM_AUTH_PUBLIC_PATHSflipped it 302 → 404 (gate lifted), while an unlisted control path stayed 302 — no over-matching. Boot log confirmed1 public routes..verify/qa-report.md.Test plan
register_public_routesrule exempts a GET read route while sibling POST/PATCH stay gated.