fix: update API Access codes to include only authenticated code (#8957)

* changed code tabs to show authenticated values

* Fixed file upload test
This commit is contained in:
Lucas Oliveira 2025-07-09 15:54:40 -03:00 • committed by GitHub
commit ef41c71701
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 24 additions and 46 deletions

View file

@ -78,7 +78,6 @@ export default function APITabsComponent() {
endpointName: endpointName || "", endpointName: endpointName || "",
streaming: streaming, streaming: streaming,
flowId: flowId || "", flowId: flowId || "",
isAuthenticated: autologin || false,
processedPayload: processedPayload, processedPayload: processedPayload,
}; };

View file

@ -40,13 +40,11 @@ export function getCurlWebhookCode({
export function getNewCurlCode({ export function getNewCurlCode({
flowId, flowId,
isAuthenticated,
endpointName, endpointName,
processedPayload, processedPayload,
platform, platform,
}: { }: {
flowId: string; flowId: string;
isAuthenticated: boolean;
endpointName: string; endpointName: string;
processedPayload: any; processedPayload: any;
platform?: "unix" | "powershell"; platform?: "unix" | "powershell";
@ -65,27 +63,19 @@ export function getNewCurlCode({
if (detectedPlatform === "powershell") { if (detectedPlatform === "powershell") {
// PowerShell with here-string (most robust for complex JSON) // PowerShell with here-string (most robust for complex JSON)
return `${ return `if (-not $env:LANGFLOW_API_KEY) {
isAuthenticated
? `if (-not $env:LANGFLOW_API_KEY) {
Write-Error "LANGFLOW_API_KEY environment variable not found" Write-Error "LANGFLOW_API_KEY environment variable not found"
exit 1 exit 1
} }
` $jsonData = @'
: ""
}$jsonData = @'
${singleLinePayload} ${singleLinePayload}
'@ '@
curl --request POST \` curl --request POST \`
--url "${apiUrl}?stream=false" \` --url "${apiUrl}?stream=false" \`
--header "Content-Type: application/json"${ --header "Content-Type: application/json" \`
isAuthenticated --header "x-api-key: $env:LANGFLOW_API_KEY" \`
? ` \`
--header "x-api-key: $env:LANGFLOW_API_KEY"`
: ""
} \`
--data $jsonData`; --data $jsonData`;
} else { } else {
// Unix-like systems (Linux, Mac, WSL2) // Unix-like systems (Linux, Mac, WSL2)
@ -94,24 +84,16 @@ curl --request POST \`
.map((line, index) => (index === 0 ? line : " " + line)) .map((line, index) => (index === 0 ? line : " " + line))
.join("\n\t\t"); .join("\n\t\t");
return `${ return `# Get API key from environment variable
isAuthenticated
? `# Get API key from environment variable
if [ -z "$LANGFLOW_API_KEY" ]; then if [ -z "$LANGFLOW_API_KEY" ]; then
echo "Error: LANGFLOW_API_KEY environment variable not found. Please set your API key in the environment variables." echo "Error: LANGFLOW_API_KEY environment variable not found. Please set your API key in the environment variables."
exit 1 exit 1
fi fi
` curl --request POST \\
: ""
}curl --request POST \\
--url '${apiUrl}?stream=false' \\ --url '${apiUrl}?stream=false' \\
--header 'Content-Type: application/json' \\${ --header 'Content-Type: application/json' \\
isAuthenticated --header "x-api-key: $LANGFLOW_API_KEY" \\
? `
--header "x-api-key: $LANGFLOW_API_KEY" \\`
: ""
}
--data '${unixFormattedPayload}'`; --data '${unixFormattedPayload}'`;
} }
} }

View file

@ -5,19 +5,16 @@ import { customGetHostProtocol } from "@/customization/utils/custom-get-host-pro
* *
* @param {Object} params - The parameters for generating the API code * @param {Object} params - The parameters for generating the API code
* @param {string} params.flowId - The ID of the flow to run * @param {string} params.flowId - The ID of the flow to run
* @param {boolean} params.isAuthenticated - Whether authentication is required
* @param {string} params.endpointName - The endpoint name for the flow * @param {string} params.endpointName - The endpoint name for the flow
* @param {Object} params.processedPayload - The pre-processed payload object * @param {Object} params.processedPayload - The pre-processed payload object
* @returns {string} Generated JavaScript code as a string * @returns {string} Generated JavaScript code as a string
*/ */
export function getNewJsApiCode({ export function getNewJsApiCode({
flowId, flowId,
isAuthenticated,
endpointName, endpointName,
processedPayload, processedPayload,
}: { }: {
flowId: string; flowId: string;
isAuthenticated: boolean;
endpointName: string; endpointName: string;
processedPayload: any; processedPayload: any;
}): string { }): string {
@ -32,21 +29,17 @@ export function getNewJsApiCode({
const payloadString = JSON.stringify(payloadWithSession, null, 4); const payloadString = JSON.stringify(payloadWithSession, null, 4);
return `${ return `// Get API key from environment variable
isAuthenticated
? `// Get API key from environment variable
if (!process.env.LANGFLOW_API_KEY) { if (!process.env.LANGFLOW_API_KEY) {
throw new Error('LANGFLOW_API_KEY environment variable not found. Please set your API key in the environment variables.'); throw new Error('LANGFLOW_API_KEY environment variable not found. Please set your API key in the environment variables.');
} }
` const payload = ${payloadString};
: ""
}const payload = ${payloadString};
const options = { const options = {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json'${isAuthenticated ? ',\n "x-api-key": process.env.LANGFLOW_API_KEY' : ""} 'Content-Type': 'application/json',\n "x-api-key": process.env.LANGFLOW_API_KEY
}, },
body: JSON.stringify(payload) body: JSON.stringify(payload)
}; };

View file

@ -2,12 +2,10 @@ import { customGetHostProtocol } from "@/customization/utils/custom-get-host-pro
export function getNewPythonApiCode({ export function getNewPythonApiCode({
flowId, flowId,
isAuthenticated,
endpointName, endpointName,
processedPayload, processedPayload,
}: { }: {
flowId: string; flowId: string;
isAuthenticated: boolean;
endpointName: string; endpointName: string;
processedPayload: any; processedPayload: any;
}): string { }): string {
@ -20,18 +18,14 @@ export function getNewPythonApiCode({
.replace(/null/g, "None"); .replace(/null/g, "None");
return `import requests return `import requests
${ import os
isAuthenticated
? `import os
# API Configuration # API Configuration
try: try:
api_key = os.environ["LANGFLOW_API_KEY"] api_key = os.environ["LANGFLOW_API_KEY"]
except KeyError: except KeyError:
raise ValueError("LANGFLOW_API_KEY environment variable not found. Please set your API key in the environment variables.") raise ValueError("LANGFLOW_API_KEY environment variable not found. Please set your API key in the environment variables.")
`
: ""
}
url = "${apiUrl}" # The complete API endpoint URL for this flow url = "${apiUrl}" # The complete API endpoint URL for this flow
# Request payload configuration # Request payload configuration
@ -39,7 +33,7 @@ payload = ${payloadString}
# Request headers # Request headers
headers = { headers = {
"Content-Type": "application/json"${isAuthenticated ? ',\n "x-api-key": api_key # Authentication key from environment variable' : ""} "Content-Type": "application/json",\n "x-api-key": api_key # Authentication key from environment variable
} }
try: try:

View file

@ -323,6 +323,16 @@ test(
}); });
await page.getByTestId(`remove-file-button-${renamedTxtFile}`).click(); await page.getByTestId(`remove-file-button-${renamedTxtFile}`).click();
await page
.getByTestId("handle-file-shownode-raw content-right")
.first()
.click();
await page
.getByTestId("handle-chatoutput-noshownode-inputs-target")
.first()
.click();
await page await page
.getByRole("button", { name: "Playground", exact: true }) .getByRole("button", { name: "Playground", exact: true })
.click(); .click();