Skip to content
Open
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
16 changes: 16 additions & 0 deletions python_a2a/server/a2a_server.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
"""
Enhanced A2A server with protocol support.
"""
Expand Down Expand Up @@ -342,6 +343,21 @@ def handle_task(self, task):
def setup_routes(self, app):
"""Setup Flask routes for A2A endpoints"""
# Root endpoint for both GET and POST
@app.before_request
def check_auth():
"""Require API key on all mutating routes."""
api_key = os.environ.get("A2A_API_KEY", "")
if not api_key:
return # No key configured = open access (dev mode)
if request.method in ("POST", "PUT", "DELETE", "PATCH"):
auth_header = request.headers.get("Authorization", "")
if auth_header.startswith("Bearer "):
token = auth_header[7:]
else:
token = auth_header
if token != api_key:
return jsonify({"error": "Unauthorized"}), 401

@app.route("/", methods=["GET"])
def a2a_root_get():
"""Root endpoint for A2A (GET), redirects to agent card"""
Expand Down