8000 feat: adding support for authorization at http layer (Python) by didier-durand · Pull Request #375 · google/A2A · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: adding support for authorization at http layer (Python) #375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions samples/python/common/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@


class A2AClient:
def __init__(self, agent_card: AgentCard = None, url: str = None):
def __init__(self, agent_card: AgentCard = None, url: str = None, auth=None):
if agent_card:
self.url = agent_card.url
elif url:
self.url = url
else:
raise ValueError("Must provide either agent_card or url")
self.auth=auth

async def send_task(self, payload: dict[str, Any]) -> SendTaskResponse:
request = SendTaskRequest(params=payload)
Expand All @@ -55,9 +56,14 @@ async def _send_request(self, request: JSONRPCRequest) -> dict[str, Any]:
async with httpx.AsyncClient() as client:
try:
# Image generation could take time, adding timeout
response = await client.post(
self.url, json=request.model_dump(), timeout=30
)
if self.auth is None:
response = await client.post(
self.url, json=request.model_dump(), timeout=30
)
else:
response = await client.post(
self.url, json=request.model_dump(), timeout=30, auth=self.auth
)
response.raise_for_status()
return response.json()
except httpx.HTTPStatusError as e:
Expand Down
1 change: 1 addition & 0 deletions samples/python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies = [
"starlette>=0.46.1",
"typing-extensions>=4.12.2",
"uvicorn>=0.34.0",
"httpx_auth>=0.23.1",
]

[tool.hatch.build.targets.wheel]
Expand Down
0