Skip to content

Open access and require auth not working inside a router #417

Closed

Description

@Robin-Van-de-Merghel

When having a parent router with require_auth set as True, we can't override its childs's require_auth.

Activity

  1. changed the title [-]Open access and require auth not working at all[/-] [+]Open access and require auth not working inside a router[/+] on Mar 26, 2025
  2. Robin-Van-de-Merghel commented on Mar 26, 2025

    @Robin-Van-de-Merghel
    ContributorAuthor

    open_access is still not used and has to be used.

    After searching for a while:

    You can't define require_auth directly in a file containing endpoints. But, if you define in your __init__.py require_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.

  3. Robin-Van-de-Merghel commented on May 13, 2025

    @Robin-Van-de-Merghel
    ContributorAuthor

    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_auth to True, and its child that sets to True.

  4. aldbr commented on Jan 29, 2026

    @aldbr
    Contributor

    IIRC, we solve that issue by creating a router named route/sub_route instead 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.

  5. linked a pull request that will close this issuefeat: add pilot database and router #570on Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions