Skip to content

Fix missing API key value prefix in try-out curl #2715

Merged
Thushani-Jayasekera merged 1 commit into
wso2:mainfrom
Tharanidk:value-bug
Jul 17, 2026
Merged

Fix missing API key value prefix in try-out curl #2715
Thushani-Jayasekera merged 1 commit into
wso2:mainfrom
Tharanidk:value-bug

Conversation

@Tharanidk

@Tharanidk Tharanidk commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Purpose

The try-out curl in the AI Workspace did not include the configured API key value prefix (e.g., Bearer), so copied commands failed gateway API key validation for providers/proxies configured with a prefix.

Changes

  • Add an apiKeyAuthDisplay utility that resolves the effective API key header name, location, and value prefix from the security config and global policies.
  • Prepend the resolved value prefix to the generated key in the curl snippets on the LLM proxy and service provider overview tabs.
  • Use the resolved header name when creating a new LLM proxy instead of the raw security.apiKey.key value.
  • URL-encode the API key when it is sent as a query parameter in the generated curl command.

UI

When added value prefix from Security tab:
image
When added as a guardrail:
image

Resolved : #2714

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

The PR centralizes API key display resolution, including header name, location, and value prefix. Proxy and service-provider views use the resolved metadata for Swagger defaults and curl snippets, while query credentials are URL-encoded.

API key authentication display

Layer / File(s) Summary
Authentication display resolution
portals/ai-workspace/src/utils/apiKeyAuthDisplay.ts
Adds shared types and helpers for resolving API key metadata and formatting prefixed credentials.
Proxy and provider integration
portals/ai-workspace/src/pages/appShell/appShellPages/proxies/*, portals/ai-workspace/src/pages/appShell/appShellPages/serviceProvider/ServiceProviderOverviewTab.tsx
Uses shared authentication metadata for generated key displays, Swagger defaults, and curl snippet inputs.
Prefixed and encoded curl commands
portals/ai-workspace/src/Components/common/ApiTryOutCurlSnippet.tsx
Adds optional prefix support, formats generated API key values, and URL-encodes query-string credentials.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ProxyOrProviderView
  participant AuthDisplayUtility
  participant SwaggerViewer
  participant ApiTryOutCurlSnippet
  ProxyOrProviderView->>AuthDisplayUtility: Resolve API key display metadata
  AuthDisplayUtility-->>ProxyOrProviderView: Return header name, location, and value prefix
  ProxyOrProviderView->>SwaggerViewer: Supply formatted generated API key
  ProxyOrProviderView->>ApiTryOutCurlSnippet: Supply API key and value prefix
  ApiTryOutCurlSnippet-->>ProxyOrProviderView: Generate prefixed and encoded curl command
Loading

Possibly related issues

Possibly related PRs

Suggested reviewers: renuka-fernando, malinthaprasan, tharindu1st

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is missing many required template sections, including Goals, Approach, User stories, Tests, Security checks, Samples, Related PRs, and Test environment. Add the missing template sections with brief details for goals, approach, user stories, tests, security checks, samples, related PRs, and test environment.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title matches the main change: adding the missing API key value prefix to the try-out curl.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
portals/ai-workspace/src/pages/appShell/appShellPages/proxies/LLMProxyOverviewTab.tsx (1)

214-230: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Add apiKeyValuePrefix to Swagger viewer remount key.

Both LLMProxyOverviewTab and ServiceProviderOverviewTab use swaggerViewerKey to force SwaggerSpecViewer to remount and pick up new default headers. Since swaggerDefaultHeaders now depends on apiKeyValuePrefix, it must be included in the string join and the useMemo dependency array to ensure the viewer reflects prefix changes.

  • portals/ai-workspace/src/pages/appShell/appShellPages/proxies/LLMProxyOverviewTab.tsx#L214-L230: Add apiKeyValuePrefix to the joined array and the dependency array of swaggerViewerKey.
  • portals/ai-workspace/src/pages/appShell/appShellPages/serviceProvider/ServiceProviderOverviewTab.tsx#L230-L246: Add apiKeyValuePrefix to the joined array and the dependency array of swaggerViewerKey.
💻 Proposed fix
   const swaggerViewerKey = useMemo(
     () =>
       [
         generatedGatewayUrl,
         apiKeyLocation,
         apiKeyName,
+        apiKeyValuePrefix,
         latestGeneratedKey ?? '',
         // proxy?.openapi ?? '' OR provider?.openapi ?? ''
       ].join('::'),
     [
       apiKeyLocation,
       apiKeyName,
+      apiKeyValuePrefix,
       generatedGatewayUrl,
       latestGeneratedKey,
       // proxy?.openapi OR provider?.openapi
     ]
   );
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@portals/ai-workspace/src/pages/appShell/appShellPages/proxies/LLMProxyOverviewTab.tsx`
around lines 214 - 230, Update swaggerViewerKey in LLMProxyOverviewTab.tsx
(lines 214-230) and ServiceProviderOverviewTab.tsx (lines 230-246) to include
apiKeyValuePrefix in both the joined remount-key values and the useMemo
dependency arrays, ensuring SwaggerSpecViewer remounts when the prefix changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In
`@portals/ai-workspace/src/pages/appShell/appShellPages/proxies/LLMProxyOverviewTab.tsx`:
- Around line 214-230: Update swaggerViewerKey in LLMProxyOverviewTab.tsx (lines
214-230) and ServiceProviderOverviewTab.tsx (lines 230-246) to include
apiKeyValuePrefix in both the joined remount-key values and the useMemo
dependency arrays, ensuring SwaggerSpecViewer remounts when the prefix changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: c2725442-159f-4edb-a14d-0fc7b5316694

📥 Commits

Reviewing files that changed from the base of the PR and between 6020bed and e834001.

📒 Files selected for processing (5)
  • portals/ai-workspace/src/Components/common/ApiTryOutCurlSnippet.tsx
  • portals/ai-workspace/src/pages/appShell/appShellPages/proxies/LLMProxyNew.tsx
  • portals/ai-workspace/src/pages/appShell/appShellPages/proxies/LLMProxyOverviewTab.tsx
  • portals/ai-workspace/src/pages/appShell/appShellPages/serviceProvider/ServiceProviderOverviewTab.tsx
  • portals/ai-workspace/src/utils/apiKeyAuthDisplay.ts

@Thushani-Jayasekera
Thushani-Jayasekera merged commit 20607fb into wso2:main Jul 17, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: API Key sample curl show wrong header and missing value prefix

2 participants