fix: use configured auth scheme prefix in API key usage examples#557
fix: use configured auth scheme prefix in API key usage examples#557argon2r wants to merge 1 commit into
Conversation
|
Warning Review limit reached
More reviews will be available in 57 minutes and 22 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
The Usage Examples panel hardcoded "Bearer" in all generated snippets, ignoring the actual auth scheme. Read the prefix from the APIKey status (status.authScheme.credentials.authorizationHeader.prefix), falling back to "Bearer" when absent, and thread it through generateAuthCodeSnippets. Signed-off-by: argon2r <armansinghof@gmail.com>
4a47e88 to
6136337
Compare
emmaaroche
left a comment
There was a problem hiding this comment.
PR handles authorizationHeader.prefix correctly (screenshot shows "APIKEY" working), but doesn't handle customHeader credential type.
When I checked my cluster, APIKeys use customHeader.name: "X-API-Key" instead of authorizationHeader. With current code, those keys will still show Authorization: Bearer YOUR_API_KEY instead of X-API-Key: YOUR_API_KEY.
Three files need changes:
-
src/utils/resources.ts- AddcustomHeader.namefield to theauthScheme.credentialstype definition -
src/components/apikey/UsageExamples.tsx- Check which credential type exists: ifcustomHeader.nameexists use that as the header name, otherwise use "Authorization" with the prefix fromauthorizationHeader.prefix -
src/utils/generateAuthCodeSnippets.ts- Add aheaderNameparameter (defaulting to "Authorization") and use it in all four snippets instead of hardcoding "Authorization". For custom headers, just use the key value; for Authorization header, use prefix + space + key.
Backstage plugin has this pattern in plugins/kuadrant/src/utils/codeSnippets.ts - see how it checks credential type and calls different snippet generators.
Description
The Usage Examples panel on the API Key details page generated cURL, Node.js, Python, and Go snippets that hardcoded
Authorization: Bearer <key>, ignoring the auth scheme actually configured by the API product's AuthPolicy. When a product uses a custom credentials prefix (e.g.APIKEY), consumers copied the snippet, sentBearer ..., and received a silent401 Unauthorizedwhich looks like a credential/config problem rather than a display bug.This PR reads the real prefix from the APIKey status (
status.authScheme.credentials.authorizationHeader.prefix) and threads it through the snippet generator, falling back toBearerwhen the field is absent (so OIDC/JWT products and older controllers are unaffected). No additional API calls are required the value is already present on the APIKey status subresource.Fixes #547
Type of change
[fix]Bug fix[feat]New feature[refactor]Refactor (no functional changes)[test]Test updates[chore]Dependency / config updateChanges made
src/utils/resources.tsaddedauthScheme.credentials.authorizationHeader.prefixto theAPIKeystatustype.src/utils/generateAuthCodeSnippets.tsadded anauthPrefix = 'Bearer'parameter, build the credential string once (handling empty-prefix schemes toavoid a stray leading space), and applied it across all four snippets. Also corrected the Python snippet, which used an
f"..."string with nointerpolation.
src/components/apikey/UsageExamples.tsxderive the prefix from the APIKey status (?? 'Bearer') and pass it togenerateAuthCodeSnippets.Test plan
yarn lintpasses (no changes after running)yarn buildpassesyarn i18npasses (no new user-facing strings snippet bodies are raw code, not translated)Screenshots
Checklist
t()and are added tolocales/en/plugin__kuadrant-console-plugin.json(no new strings introduced)kuadrant-no bare.pf-*or.co-*selectors, no hex colors (no CSS changes)console.logstatements left inSigned-off-byline (git commit -s)