feat(server): allow standard FastAPI Security in routes by ianchi · Pull Request #785 · a2aproject/a2a-python · GitHub
Skip to content

feat(server): allow standard FastAPI Security in routes - #785

Closed
ianchi wants to merge 3 commits into
a2aproject:mainfrom
ianchi:fastapi-auth
Closed

feat(server): allow standard FastAPI Security in routes#785
ianchi wants to merge 3 commits into
a2aproject:mainfrom
ianchi:fastapi-auth

Conversation

@ianchi

@ianchi ianchi commented Mar 7, 2026

Copy link
Copy Markdown

Description

Current FastAPI app does not allow to use standard FastAPI Security mechanism to authenticate distinct routes. You could add as middleware but it would apply to all routes, even the agent card.
Add a dependency parameter, to allow to pass dependency that will only be added to main endpoint and the extended agent card, but not the general one.

Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Follow the CONTRIBUTING Guide.
  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.
    • Important Prefixes for release-please:
      • fix: which represents bug fixes, and correlates to a SemVer patch.
      • feat: represents a new feature, and correlates to a SemVer minor.
      • feat!:, or fix!:, refactor!:, etc., which represent a breaking change (indicated by the !) and will result in a SemVer major.
  • Ensure the tests and linter pass (Run bash scripts/format.sh from the repository root to format)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@ianchi
ianchi requested a review from a team as a code owner March 7, 2026 16:39
@gemini-code-assist

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a valuable feature by allowing FastAPI dependencies to be passed to secure specific routes, specifically applying them to the RPC and extended agent card endpoints. The implementation is clean, and a thorough security audit confirmed that this addition is a security improvement for authentication and authorization, introducing no new vulnerabilities. I have a couple of minor suggestions to improve type hinting for the new dependencies parameter and to enhance consistency in the documentation examples.

Comment thread src/a2a/server/apps/jsonrpc/fastapi_app.py Outdated
Comment thread src/a2a/server/apps/jsonrpc/fastapi_app.py Outdated
@ianchi

ianchi commented Mar 8, 2026

Copy link
Copy Markdown
Author

updated with suggestions

@holtskinner

holtskinner commented Mar 12, 2026

Copy link
Copy Markdown
Member

@ianchi Thanks for the contribution! Can you also add a test for this use case?

And can you update the rest/fastapi_app.py to include these parameters, if relevant.

@ianchi

ianchi commented Mar 12, 2026

Copy link
Copy Markdown
Author

Hi @holtskinner, I see you already included everything.
Let me know if something else is needed.

@holtskinner holtskinner assigned herczyn and ishymko and unassigned ianchi Mar 13, 2026
@holtskinner

Copy link
Copy Markdown
Member

@ishymko @herczyn Can you take a look at this please?

@holtskinner
holtskinner requested review from herczyn and ishymko March 13, 2026 16:55
@ishymko

ishymko commented Mar 18, 2026

Copy link
Copy Markdown
Member

@guglielmo-san could you please check if this scenario is going to be enabled as a part of #797? I'd try to expose native APIs and just plug our things so that it can be used side by side with existing FastAPI apps.

@ishymko ishymko assigned guglielmo-san and unassigned herczyn and ishymko Mar 18, 2026
@ianchi

ianchi commented Mar 27, 2026

Copy link
Copy Markdown
Author

Hi, any comments on this?

Can I help somhow?

@guglielmo-san

Copy link
Copy Markdown
Member

@ianchi we changed the server implementation (#873 and #892) which will be available in the next alpha release. The new server will return Starlette Routes which you can modify in your server implementation adding the middlewares to specific Routes.
Let me know if this new implementation meets your requirements.

@ishymko
ishymko removed the request for review from herczyn April 2, 2026 10:26
@guglielmo-san

Copy link
Copy Markdown
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants