Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix: fix auth prefix duplicate (#38616)

wangxiaolei7bfbb2bbe832
diff --git a/api/core/tools/custom_tool/tool.py b/api/core/tools/custom_tool/tool.py
index 38a13609dbf..0e1da00a3fc 100644
--- a/api/core/tools/custom_tool/tool.py
+++ b/api/core/tools/custom_tool/tool.py
@@ -103,16 +103,17 @@ class ApiTool(Tool):
elif not isinstance(credentials["api_key_value"], str):
raise ToolProviderCredentialValidationError("api_key_value must be a string")
+ api_key_value = credentials["api_key_value"]
if "api_key_header_prefix" in credentials:
api_key_header_prefix = credentials["api_key_header_prefix"]
- if api_key_header_prefix == "basic" and credentials["api_key_value"]:
- credentials["api_key_value"] = f"Basic {credentials['api_key_value']}"
- elif api_key_header_prefix == "bearer" and credentials["api_key_value"]:
- credentials["api_key_value"] = f"Bearer {credentials['api_key_value']}"
+ if api_key_header_prefix == "basic" and api_key_value:
+ api_key_value = f"Basic {api_key_value}"
+ elif api_key_header_prefix == "bearer" and api_key_value:
+ api_key_value = f"Bearer {api_key_value}"
elif api_key_header_prefix == "custom":
pass
- headers[api_key_header] = credentials["api_key_value"]
+ headers[api_key_header] = api_key_value
elif credentials["auth_type"] == "api_key_query":
# For query parameter authentication, we don't add anything to headers
diff --git a/api/tests/unit_tests/core/tools/test_custom_tool.py b/api/tests/unit_tests/core/tools/test_custom_tool.py
index 3f664456bd2..64cd128f18e 100644
--- a/api/tests/unit_tests/core/tools/test_custom_tool.py
+++ b/api/tests/unit_tests/core/tools/test_custom_tool.py
@@ -85,6 +85,10 @@ def test_assembling_request_auth_header_assembly():
assert headers["Authorization"] == "Bearer abc"
tool.runtime.credentials = {"auth_type": "api_key_header", "api_key_header_prefix": "basic", "api_key_value": "abc"}
+ headers = tool.assembling_request(parameters={})
+ assert headers["Authorization"] == "Basic abc"
+ assert tool.runtime.credentials["api_key_value"] == "abc"
+
headers = tool.assembling_request(parameters={})
assert headers["Authorization"] == "Basic abc"