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
I’m trying to deploy an A2A agent using Google ADK, and I’m struggling to find clear documentation around authentication, token propagation, and session handling.
🎯 What I Need
I would like to:
Handle authentication to access the agent (JWT-based).
Propagate the auth token to custom remote MCP servers.
Access decoded JWT payload fields inside my tools.
Let the agent handle sessions automatically (A2A-native sessions).
✅ What I Implemented So Far
1️⃣ Convert Agent to A2A
I converted my root agent to A2A using to_a2a:
defcreate_app(root_agent) ->Optional[object]:
try:
fromgoogle.adk.a2a.utils.agent_to_a2aimportto_a2alogger.info(f"Creating A2A application for {config.SERVICE_NAME}")
# Convert agent to A2A protocolapp=to_a2a(
root_agent,
port=config.SERVICE_PORT,
host=config.SERVICE_HOST,
)
app.routes.append(Route("/health", health_check, methods=["GET"]))
app.add_middleware(JWTAuthMiddleware)
logger.info(
f"A2A application created successfully on {config.SERVICE_HOST}:{config.SERVICE_PORT}"
)
returnappexceptImportErrorase:
logger.warning(f"Server mode dependencies not available: {e}")
logger.warning("Agent will only work in local/CLI mode")
returnNone
2️⃣ Custom JWT Middleware
I implemented a JWTAuthMiddleware using ContextVar to propagate the decoded payload across the agent execution:
When running the agent locally using adk web to test it, the jwt middleware is bypassed.
When running the server using uvicorn my_agent.agent:app --reload --host 0.0.0.0 --port 8080, I need to send call using A2A protocol and that doesn't handle the sessions.
🤔 Main Questions
Is using a ContextVar + before_agent_callback the correct pattern for propagating JWT payload into tools?
Is there a more “ADK-native” way to handle authentication?
What is the recommended way to:
Validate JWT
Inject decoded payload into agent state
Propagate token to remote MCP tools
How should auth integrate with A2A session handling?
Is adk web compatible with custom FastAPI middleware, or is it intended only for local/dev use?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi 👋
I’m trying to deploy an A2A agent using Google ADK, and I’m struggling to find clear documentation around authentication, token propagation, and session handling.
🎯 What I Need
I would like to:
✅ What I Implemented So Far
1️⃣ Convert Agent to A2A
I converted my root agent to A2A using
to_a2a:2️⃣ Custom JWT Middleware
I implemented a
JWTAuthMiddlewareusingContextVarto propagate the decoded payload across the agent execution:3️⃣ Inject User Info into Agent Context
I added a
before_agent_callbackto push user info into the agent state:With this setup. I'm having some issues:
🤔 Main Questions
Beta Was this translation helpful? Give feedback.
All reactions