Skip to content

feat: support authentication on server side#195

Merged
guglielmo-san merged 22 commits intoa2aproject:mainfrom
guglielmo-san:implement_support_for_authentication_on_server_side
Nov 25, 2025
Merged

feat: support authentication on server side#195
guglielmo-san merged 22 commits intoa2aproject:mainfrom
guglielmo-san:implement_support_for_authentication_on_server_side

Conversation

@guglielmo-san
Copy link
Member

@guglielmo-san guglielmo-san commented Nov 21, 2025

Description

This PR integrates a support for authentication on the server side.
A new User interface is created to represent the Authenticated and UnAuthenticated user in the context, with 2 required function:

  1. isAuthenticathed()
  2. userName()

The callback authenticathedUserExtractor provided to the A2AExpressApp is responsible for extracting the user object from the Request (if set up by the authentication middleware), and returning an instance of the User interface. The returned instance will be added to the ServerCallContext.
If no authentication middleware or no authenticathedUserExtractor is provided to the Server, the user in the ServerCallContext will be of type UnAuthenticated.

Fixes #194 🦕

Release-As: 0.3.6

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @guglielmo-san, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the server's security posture by introducing support for basic bearer token authentication. By integrating industry-standard libraries like express-openapi-validator and passport, it ensures that API requests are properly authenticated against defined security schemes. This change provides a foundational layer for securing server-side operations and managing user access based on token validity.

Highlights

  • Server-Side Bearer Authentication: Implemented basic bearer token authentication on the server side to secure API endpoints. This feature leverages OpenAPI 3.0 definitions for security analysis.
  • OpenAPI Validator Integration: Integrated express-openapi-validator to analyze security and security schemes based on the OpenAPI 3.0 definition, ensuring requests conform to defined security policies.
  • Passport.js for Token Verification: Utilized the passport plugin with a JwtStrategy to verify the validity of bearer tokens, allowing for robust authentication flows.
  • User Context Enhancement: Introduced User, AuthenticatedUser, and unAuthenticatedUser types to enrich the ServerCallContext, providing clear authentication status for incoming requests.
  • Dynamic OpenAPI Spec Generation: The A2AExpressApp now dynamically generates an OpenAPI specification based on the agent's AgentCard security definitions, which is then used by the validator middleware.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 bearer token authentication, which is a great addition. The implementation using express-openapi-validator and passport is mostly solid and includes good test coverage. However, I've identified a critical security vulnerability with a hardcoded JWT secret that must be addressed. I've also provided suggestions to improve efficiency by removing unnecessary file I/O, to enhance functionality by preserving user data from the JWT payload, and to align with common naming conventions. Overall, these are valuable changes that will be even better with these improvements.

@guglielmo-san
Copy link
Member Author

/gemini review

Copy link
Contributor

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

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 solid implementation for basic bearer authentication on the server side. The changes are well-structured, with a clear separation of concerns by introducing an A2AUser interface and related classes to abstract user information. The ServerCallContext is appropriately updated to carry user details, and the JSON-RPC handler is cleanly modified to build this context from the incoming request. The accompanying tests effectively validate the new functionality for both authenticated and unauthenticated scenarios. My feedback focuses on enhancing the robustness of the ProxyUser class to ensure type safety when dealing with user objects from various authentication middlewares.

@guglielmo-san guglielmo-san changed the title feat: Implement support for basic bearer authentication on server side feat: Implement support for authentication on server side Nov 23, 2025
@ishymko ishymko changed the title feat: Implement support for authentication on server side feat: support authentication on server side Nov 25, 2025
@guglielmo-san guglielmo-san merged commit 9872d93 into a2aproject:main Nov 25, 2025
5 checks passed
@guglielmo-san guglielmo-san deleted the implement_support_for_authentication_on_server_side branch November 25, 2025 10:42
@ishymko ishymko mentioned this pull request Nov 26, 2025
4 tasks
guglielmo-san added a commit to guglielmo-san/a2a-js that referenced this pull request Nov 26, 2025
This PR integrates a support for authentication on the server side.
A new `User` interface is created to represent the Authenticated and
UnAuthenticated user in the context, with 2 required function:
1. isAuthenticathed()
2. userName()

The callback `authenticathedUserExtractor` provided to the
`A2AExpressApp` is responsible for extracting the user object from the
Request (if set up by the authentication middleware), and returning an
instance of the `User` interface. The returned instance will be added to
the ServerCallContext.
If no authentication middleware or no `authenticathedUserExtractor` is
provided to the Server, the user in the ServerCallContext will be of
type UnAuthenticated.

Fixes a2aproject#194  🦕

Release-As: 0.3.6
guglielmo-san added a commit that referenced this pull request Nov 27, 2025
…ontext is created (#200)

# Description

This PR is a fix for the bug caused by the user being deleted when the
request is containing requested extensions, as a new ServerCallContext
was created without copying the `context.user`.

Fixes #199 🦕
PRs #171, #195 

BEGIN_COMMIT_OVERRIDE
refactor: Populate the ServerCallContext user param when a new
ServerCallContext is created
END_COMMIT_OVERRIDE
ishymko added a commit that referenced this pull request Nov 27, 2025
# Description

Marking as refactor, since updated type wasn't released yet.

Making `userBuilder` a mandatory parameter for `JsonRpcHandlerOptions`
and define a helper `UserBuilder.NoAuthentication` to make it explicit.

Re #195.
guglielmo-san added a commit to guglielmo-san/a2a-js that referenced this pull request Nov 27, 2025
…ontext is created (a2aproject#200)

This PR is a fix for the bug caused by the user being deleted when the
request is containing requested extensions, as a new ServerCallContext
was created without copying the `context.user`.

Fixes a2aproject#199 🦕
PRs a2aproject#171, a2aproject#195

BEGIN_COMMIT_OVERRIDE
refactor: Populate the ServerCallContext user param when a new
ServerCallContext is created
END_COMMIT_OVERRIDE
guglielmo-san pushed a commit to guglielmo-san/a2a-js that referenced this pull request Nov 27, 2025
# Description

Marking as refactor, since updated type wasn't released yet.

Making `userBuilder` a mandatory parameter for `JsonRpcHandlerOptions`
and define a helper `UserBuilder.NoAuthentication` to make it explicit.

Re a2aproject#195.
guglielmo-san added a commit to guglielmo-san/a2a-js that referenced this pull request Nov 27, 2025
This PR integrates a support for authentication on the server side.
A new `User` interface is created to represent the Authenticated and
UnAuthenticated user in the context, with 2 required function:
1. isAuthenticathed()
2. userName()

The callback `authenticathedUserExtractor` provided to the
`A2AExpressApp` is responsible for extracting the user object from the
Request (if set up by the authentication middleware), and returning an
instance of the `User` interface. The returned instance will be added to
the ServerCallContext.
If no authentication middleware or no `authenticathedUserExtractor` is
provided to the Server, the user in the ServerCallContext will be of
type UnAuthenticated.

Fixes a2aproject#194  🦕

Release-As: 0.3.6
guglielmo-san added a commit to guglielmo-san/a2a-js that referenced this pull request Nov 27, 2025
This PR integrates a support for authentication on the server side.
A new `User` interface is created to represent the Authenticated and
UnAuthenticated user in the context, with 2 required function:
1. isAuthenticathed()
2. userName()

The callback `authenticathedUserExtractor` provided to the
`A2AExpressApp` is responsible for extracting the user object from the
Request (if set up by the authentication middleware), and returning an
instance of the `User` interface. The returned instance will be added to
the ServerCallContext.
If no authentication middleware or no `authenticathedUserExtractor` is
provided to the Server, the user in the ServerCallContext will be of
type UnAuthenticated.

Fixes a2aproject#194  🦕

Release-As: 0.3.6
guglielmo-san added a commit to guglielmo-san/a2a-js that referenced this pull request Nov 27, 2025
…ontext is created (a2aproject#200)

This PR is a fix for the bug caused by the user being deleted when the
request is containing requested extensions, as a new ServerCallContext
was created without copying the `context.user`.

Fixes a2aproject#199 🦕
PRs a2aproject#171, a2aproject#195

BEGIN_COMMIT_OVERRIDE
refactor: Populate the ServerCallContext user param when a new
ServerCallContext is created
END_COMMIT_OVERRIDE
guglielmo-san added a commit that referenced this pull request Dec 1, 2025
# Description

This PR introduces a sample for the authentication feature.

Re #195

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
ishymko added a commit that referenced this pull request Dec 10, 2025
🤖 I have created a release *beep* *boop*
---


## [0.3.6](v0.3.5...v0.3.6)
(2025-12-10)


### Features

* add support for extendedAgentCard on client side
([#234](#234))
([3073376](3073376))
* Add support for extension headers on client side
([#227](#227))
([8c57002](8c57002))
* implement client interceptors
([#223](#223))
([5694c22](5694c22))
* Implement extended card support on server side
([#197](#197))
([45014ac](45014ac))
* implement server http+json
([#142](#142))
([f20e662](f20e662))
* introduce AgentCardResolver
([#225](#225))
([ddaf7de](ddaf7de))
* introduce transport agnostic client
([#198](#198))
([94a9848](94a9848))
* server side support for extensions
([5ef7396](5ef7396))
* support authentication on server side
([#195](#195))
([9872d93](9872d93))


### Bug Fixes

* handle errors occurred in non-blocking sendMessage
([#187](#187))
([e55c0f4](e55c0f4))


### Miscellaneous Chores

* set version to 0.3.6
([#191](#191))
([3f8cea0](3f8cea0))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: Ivan Shymko <ishymko@google.com>
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.

[Feat]: Support authentication on server side

2 participants