Implement AuthenticationMiddleware (#117)#171
Conversation
Adds a public ClientMiddleware that injects the x-api-key and anthropic-version headers into every outgoing ClaudeKit request. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ 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 |
Code Review: Implement AuthenticationMiddleware (#117)OverviewAdds IssuesSilent header omission is a latent security bugif let name = HTTPField.Name("x-api-key") {
request.headerFields[name] = apiKey
}
// Safety: these literals satisfy HTTPField.Name's ASCII constraints.
let apiKeyName = HTTPField.Name("x-api-key")!
let versionName = HTTPField.Name("anthropic-version")!
|
Code Review —
|
| Severity | Issue |
|---|---|
| Required | Add unit tests per CLAUDE.md convention |
| Medium | Silent auth bypass if HTTPField.Name init returns nil — at minimum document the invariant |
| Low | Make anthropicVersion configurable via init |
| Nit | Fix module name in file header |
The core logic is correct and the implementation matches the protocol shape accurately. Addressing the missing tests and the silent-failure path are the blockers before merge.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## claude-prompt #171 +/- ##
=================================================
- Coverage 80.16% 79.95% -0.22%
=================================================
Files 153 153
Lines 5209 5209
=================================================
- Hits 4176 4165 -11
- Misses 1033 1044 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Code Review — PR 171: Implement AuthenticationMiddleware Straightforward, correct implementation. One concern worth addressing. Potential silent auth failure The if let name = HTTPField.Name("x-api-key") {
request.headerFields[name] = apiKey
}
// if name is nil, the request goes out WITHOUT the x-api-key headerThe PR description explains this was chosen to satisfy SwiftLint's Recommendation: Replace the Minor observations
|
Closes #117
Summary
Adds
Sources/AiSTKit/AuthenticationMiddleware.swift— apublicOpenAPIClientMiddlewarethat injects the Anthropic authentication headers into every outgoing request:x-api-keywith the stored API keyanthropic-version: 2023-06-01The request is then forwarded to the next handler via
next(request, body, baseURL). The middleware will be wired into the generated ClaudeKit client by theClaudeKitwrapper in #116.Implementation notes
ClientMiddlewaresignature (includesbody: HTTPBody?and returns(HTTPResponse, HTTPBody?)) — the simplified snippet inDocs/skit-analyze-plan.md§I2 predates the current protocol shape.public importforOpenAPIRuntime,HTTPTypes, andFoundation.URLsince the package builds withInternalImportsByDefaultand these types appear in the public conformance.HTTPField.Name(SwiftLintforce_unwrappingrule) viaif leton the always-valid header names.Acceptance criteria
Verification
swift build— cleanswift test— 489 tests pass./Scripts/lint.sh— SwiftFormat, SwiftLint, header check, and test build pass (Periphery's "index store path does not exist" error reproduces on a clean checkout, pre-existing local environment issue; Periphery is skipped in CI)🤖 Generated with Claude Code