fix: authenticates swagger ui to access secured endpoints#122
Conversation
Signed-off-by: Amit Singh <singhamitch@outlook.com>
|
Warning Review limit reached
More reviews will be available in 33 minutes and 43 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis PR refactors the Swagger UI endpoint to use an embedded HTML file instead of an inlined template. It adds OpenAPI spec runtime loading with automatic authorization, an auto-authorize plugin that fetches auth tokens and preauthorizes requests, and a request interceptor that injects the Client-ID header. The API spec now includes a default Client-ID value. ChangesSwagger UI with Auto-Authorization
Sequence DiagramsequenceDiagram
participant Browser as Browser/User
participant SwaggerUI as Swagger UI Bundle
participant Backend as Backend API
Browser->>SwaggerUI: Load page
SwaggerUI->>Backend: GET /swagger/spec
Backend-->>SwaggerUI: OpenAPI spec (YAML)
SwaggerUI->>SwaggerUI: Parse spec and remove /auth/token path
Browser->>SwaggerUI: Click Authorize button
SwaggerUI->>Backend: POST /auth/token (with Client-ID: swagger-ui)
Backend-->>SwaggerUI: {token: "..."}
SwaggerUI->>SwaggerUI: preauthorizeApiKey(BearerAuth, token)
SwaggerUI->>Browser: Show authorization success
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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.
Inline comments:
In `@pkg/handlers/swagger-ui.html`:
- Around line 38-39: Update the script tag in pkg/handlers/swagger-ui.html that
loads https://cdnjs.cloudflare.com/ajax/libs/js-yaml/4.1.0/js-yaml.min.js to
include a Subresource Integrity attribute: compute the SHA-512 hash for that
exact minified file and add integrity="sha512-..." plus crossorigin="anonymous"
(keep existing referrerpolicy if present) so the script matches the other
swagger-ui-dist scripts using integrity; locate the script by the src URL and
add the integrity attribute with the exact computed hash for js-yaml.min.js
v4.1.0.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 8404914f-9c75-4da3-965f-f8ffec27b485
📒 Files selected for processing (3)
api/source-score.yamlpkg/handlers/swagger-ui.htmlpkg/handlers/swagger.go
7abdbf0 to
7d2dcfe
Compare
|
@semmet95 I have started the AI code review. It will take a few minutes to complete. |
There was a problem hiding this comment.
1 issue found across 3 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Signed-off-by: Amit Singh <singhamitch@outlook.com>
7d2dcfe to
282e5bd
Compare
Summary by CodeRabbit
New Features
Improvements