Sfoglia il codice sorgente

fix verify mcp connection with oauth type (#19149)

Oleg Yermolenko 3 mesi fa
parent
commit
8dde493e8e
1 ha cambiato i file con 9 aggiunte e 4 eliminazioni
  1. 9 4
      backend/open_webui/routers/configs.py

+ 9 - 4
backend/open_webui/routers/configs.py

@@ -270,17 +270,18 @@ async def verify_tool_servers_config(
                     elif form_data.auth_type == "session":
                         token = request.state.token.credentials
                     elif form_data.auth_type == "system_oauth":
+                        oauth_token = None
                         try:
                             if request.cookies.get("oauth_session_id", None):
-                                token = await request.app.state.oauth_manager.get_oauth_token(
+                                oauth_token = await request.app.state.oauth_manager.get_oauth_token(
                                     user.id,
                                     request.cookies.get("oauth_session_id", None),
                                 )
                         except Exception as e:
                             pass
 
-                    if token:
-                        headers = {"Authorization": f"Bearer {token}"}
+                    if oauth_token:
+                        headers = {"Authorization": f"Bearer {oauth_token.get('access_token', '')}"}
 
                     await client.connect(form_data.url, headers=headers)
                     specs = await client.list_tool_specs()
@@ -306,10 +307,14 @@ async def verify_tool_servers_config(
             elif form_data.auth_type == "system_oauth":
                 try:
                     if request.cookies.get("oauth_session_id", None):
-                        token = await request.app.state.oauth_manager.get_oauth_token(
+                        oauth_token = await request.app.state.oauth_manager.get_oauth_token(
                             user.id,
                             request.cookies.get("oauth_session_id", None),
                         )
+                        
+                        if oauth_token:
+                            token = f"{oauth_token.get('access_token', '')}"
+
                 except Exception as e:
                     pass