|
22 | 22 | from a2a.types import AgentCapabilities, AgentCard, AgentSkill, TaskState, TextPart, SecurityScheme, HTTPAuthSecurityScheme |
23 | 23 | from a2a.utils import new_agent_text_message, new_task |
24 | 24 |
|
25 | | -from starlette.authentication import AuthCredentials, SimpleUser, AuthenticationBackend |
26 | 25 | from starlette.middleware.authentication import AuthenticationMiddleware |
27 | 26 |
|
28 | 27 | from git_issue_agent.auth import on_auth_error, BearerAuthBackend, auth_headers |
|
33 | 32 | logger = logging.getLogger(__name__) |
34 | 33 | logging.basicConfig(level=settings.LOG_LEVEL, stream=sys.stdout, format='%(levelname)s: %(message)s') |
35 | 34 |
|
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 | | - |
55 | 35 | def get_agent_card(host: str, port: int): |
56 | 36 | """Returns the Agent Card for the AG2 Agent.""" |
57 | 37 | capabilities = AgentCapabilities(streaming=True) |
@@ -158,14 +138,10 @@ async def execute(self, context: RequestContext, event_queue: EventQueue): |
158 | 138 | Returns: |
159 | 139 | None |
160 | 140 | """ |
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 |
169 | 145 | user_input = [context.get_user_input()] |
170 | 146 | task = context.current_task |
171 | 147 | if not task: |
|
0 commit comments