You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Open access and require auth not working inside a router #417
You can't define require_auth directly in a file containing endpoints. But, if you define in your __init__.pyrequire_auth=False, then it will work.
I guess, we should redefine include_router to use DiracxRouter instead of APIRouter in the case where we need to have routers with and without auth depending on the file.
Activity
[-]Open access and require auth not working at all[/-][+]Open access and require auth not working inside a router[/+]Robin-Van-de-Merghel commentedon Mar 26, 2025
open_accessis still not used and has to be used.After searching for a while:
You can't define
require_authdirectly in a file containing endpoints. But, if you define in your__init__.pyrequire_auth=False, then it will work.I guess, we should redefine
include_routerto useDiracxRouterinstead ofAPIRouterin the case where we need to have routers with and without auth depending on the file.Robin-Van-de-Merghel commentedon May 13, 2025
In fastapi, the sub_router has his dependencies extended from the parent:
https://github.com/fastapi/fastapi/blob/ea7b1054762c72a79bc111e747e20d4c67721afc/fastapi/routing.py#L1272-L1301
So, it will be hard to have a parent that sets
require_authtoTrue, and its child that sets toTrue.aldbr commentedon Jan 29, 2026
IIRC, we solve that issue by creating a router named
route/sub_routeinstead of creating a subrouter.Solution is described in this commit: 4507b79#diff-dd773308652c604bc463e6331344e7b9f933ba9bbee8f59f13cb6c9d0d83d6c5R50
This is documented in an open PR: https://github.com/DIRACGrid/diracx/pull/570/changes#diff-8f74d39cd838a4e8a01dc451b6ba5e5576803d818809110a85143931f8452ba6R10
Can be marked as solved if the changes are merged.