Skip to content

Commit 8b8c8f3

Browse files
authored
Merge pull request #83 from maia-iyer/add_auth_to_git_agent
⚠️ Pass tokens to MCP Server in Git Agent
2 parents 5e73c34 + f7a2e19 commit 8b8c8f3

1 file changed

Lines changed: 4 additions & 28 deletions

File tree

a2a/git_issue_agent/a2a_agent.py

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from a2a.types import AgentCapabilities, AgentCard, AgentSkill, TaskState, TextPart, SecurityScheme, HTTPAuthSecurityScheme
2323
from a2a.utils import new_agent_text_message, new_task
2424

25-
from starlette.authentication import AuthCredentials, SimpleUser, AuthenticationBackend
2625
from starlette.middleware.authentication import AuthenticationMiddleware
2726

2827
from git_issue_agent.auth import on_auth_error, BearerAuthBackend, auth_headers
@@ -33,25 +32,6 @@
3332
logger = logging.getLogger(__name__)
3433
logging.basicConfig(level=settings.LOG_LEVEL, stream=sys.stdout, format='%(levelname)s: %(message)s')
3534

36-
class BearerAuthBackend(AuthenticationBackend):
37-
""" Very temporary demo to grab auth token and print it"""
38-
async def authenticate(self, conn):
39-
try:
40-
auth = conn.headers.get("authorization")
41-
if not auth or not auth.lower().startswith("bearer "):
42-
print("No bearer token provided")
43-
return
44-
token = auth.split(" ", 1)[1]
45-
print(f"TOKEN: {token}")
46-
47-
# Storing the token as the username - not a real life scenario - just demo-ing the passing of creds
48-
user = SimpleUser(token)
49-
return AuthCredentials(["authenticated"]), user
50-
except Exception as e:
51-
logger.error("Exception when attempting to obtain user token")
52-
logger.error(e)
53-
54-
5535
def get_agent_card(host: str, port: int):
5636
"""Returns the Agent Card for the AG2 Agent."""
5737
capabilities = AgentCapabilities(streaming=True)
@@ -158,14 +138,10 @@ async def execute(self, context: RequestContext, event_queue: EventQueue):
158138
Returns:
159139
None
160140
"""
161-
###
162-
# commenting this out for now since we have external github MCP.
163-
# in the future we need to figure out the token exchange story for this scenario
164-
#
165-
#if settings.JWKS_URI:
166-
# user_token = context.call_context.user._user.access_token
167-
#else:
168-
user_token = settings.GITHUB_TOKEN
141+
if settings.JWKS_URI:
142+
user_token = context.call_context.user._user.access_token
143+
else:
144+
user_token = settings.GITHUB_TOKEN
169145
user_input = [context.get_user_input()]
170146
task = context.current_task
171147
if not task:

0 commit comments

Comments
 (0)