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 || "",
streaming: streaming,
flowId: flowId || "",
isAuthenticated: autologin || false,
processedPayload: processedPayload,
};

View file

@ -40,13 +40,11 @@ export function getCurlWebhookCode({
export function getNewCurlCode({
flowId,
isAuthenticated,
endpointName,
processedPayload,
platform,
}: {
flowId: string;
isAuthenticated: boolean;
endpointName: string;
processedPayload: any;
platform?: "unix" | "powershell";
@ -65,27 +63,19 @@ export function getNewCurlCode({
if (detectedPlatform === "powershell") {
// PowerShell with here-string (most robust for complex JSON)
return `${
isAuthenticated
? `if (-not $env:LANGFLOW_API_KEY) {
return `if (-not $env:LANGFLOW_API_KEY) {
Write-Error "LANGFLOW_API_KEY environment variable not found"
exit 1
}
`
: ""
}$jsonData = @'
$jsonData = @'
${singleLinePayload}
'@
curl --request POST \`
--url "${apiUrl}?stream=false" \`
--header "Content-Type: application/json"${
isAuthenticated
? ` \`
--header "x-api-key: $env:LANGFLOW_API_KEY"`
: ""
} \`
--header "Content-Type: application/json" \`
--header "x-api-key: $env:LANGFLOW_API_KEY" \`
--data $jsonData`;
} else {
// Unix-like systems (Linux, Mac, WSL2)
@ -94,24 +84,16 @@ curl --request POST \`
.map((line, index) => (index === 0 ? line : " " + line))
.join("\n\t\t");
return `${
isAuthenticated
? `# Get API key from environment variable
return `# Get API key from environment variable
if [ -z "$LANGFLOW_API_KEY" ]; then
echo "Error: LANGFLOW_API_KEY environment variable not found. Please set your API key in the environment variables."
exit 1
fi
`
: ""
}curl --request POST \\
curl --request POST \\
--url '${apiUrl}?stream=false' \\
--header 'Content-Type: application/json' \\${
isAuthenticated
? `
--header "x-api-key: $LANGFLOW_API_KEY" \\`
: ""
}
--header 'Content-Type: application/json' \\
--header "x-api-key: $LANGFLOW_API_KEY" \\
--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 {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 {Object} params.processedPayload - The pre-processed payload object
* @returns {string} Generated JavaScript code as a string
*/
export function getNewJsApiCode({
flowId,
isAuthenticated,
endpointName,
processedPayload,
}: {
flowId: string;
isAuthenticated: boolean;
endpointName: string;
processedPayload: any;
}): string {
@ -32,21 +29,17 @@ export function getNewJsApiCode({
const payloadString = JSON.stringify(payloadWithSession, null, 4);
return `${
isAuthenticated
? `// Get API key from environment variable
return `// Get API key from environment variable
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.');
}
`
: ""
}const payload = ${payloadString};
const payload = ${payloadString};
const options = {
method: 'POST',
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)
};

View file

@ -2,12 +2,10 @@ import { customGetHostProtocol } from "@/customization/utils/custom-get-host-pro
export function getNewPythonApiCode({
flowId,
isAuthenticated,
endpointName,
processedPayload,
}: {
flowId: string;
isAuthenticated: boolean;
endpointName: string;
processedPayload: any;
}): string {
@ -20,18 +18,14 @@ export function getNewPythonApiCode({
.replace(/null/g, "None");
return `import requests
${
isAuthenticated
? `import os
import os
# API Configuration
try:
api_key = os.environ["LANGFLOW_API_KEY"]
except KeyError:
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
# Request payload configuration
@ -39,7 +33,7 @@ payload = ${payloadString}
# Request 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:

View file

@ -323,6 +323,16 @@ test(
});
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
.getByRole("button", { name: "Playground", exact: true })
.click();