fix verify mcp connection with oauth type (#19149)
This commit is contained in:
@@ -270,17 +270,18 @@ async def verify_tool_servers_config(
|
|||||||
elif form_data.auth_type == "session":
|
elif form_data.auth_type == "session":
|
||||||
token = request.state.token.credentials
|
token = request.state.token.credentials
|
||||||
elif form_data.auth_type == "system_oauth":
|
elif form_data.auth_type == "system_oauth":
|
||||||
|
oauth_token = None
|
||||||
try:
|
try:
|
||||||
if request.cookies.get("oauth_session_id", None):
|
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,
|
user.id,
|
||||||
request.cookies.get("oauth_session_id", None),
|
request.cookies.get("oauth_session_id", None),
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if token:
|
if oauth_token:
|
||||||
headers = {"Authorization": f"Bearer {token}"}
|
headers = {"Authorization": f"Bearer {oauth_token.get('access_token', '')}"}
|
||||||
|
|
||||||
await client.connect(form_data.url, headers=headers)
|
await client.connect(form_data.url, headers=headers)
|
||||||
specs = await client.list_tool_specs()
|
specs = await client.list_tool_specs()
|
||||||
@@ -306,10 +307,14 @@ async def verify_tool_servers_config(
|
|||||||
elif form_data.auth_type == "system_oauth":
|
elif form_data.auth_type == "system_oauth":
|
||||||
try:
|
try:
|
||||||
if request.cookies.get("oauth_session_id", None):
|
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,
|
user.id,
|
||||||
request.cookies.get("oauth_session_id", None),
|
request.cookies.get("oauth_session_id", None),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if oauth_token:
|
||||||
|
token = f"{oauth_token.get('access_token', '')}"
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user