fix: resolve ApiToken reserved header exception (#146)#152
fix: resolve ApiToken reserved header exception (#146)#152daniel-jonathan merged 2 commits intomainfrom
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughRefactors ApiToken and OAuth token handling in ApiClient to resolve a conflict where ApiToken credentials were incorrectly set in DefaultHeaders and rejected by validation. Introduces centralized token retrieval via GetAuthenticationTokenAsync and updates header construction logic to apply authorization tokens at request time rather than modifying DefaultHeaders, with comprehensive test coverage for ApiToken, OAuth, and no-credential scenarios. Changes
Sequence Diagram(s)sequenceDiagram
actor User
participant Config as Configuration
participant Client as ApiClient
participant Auth as GetAuthenticationToken
participant Build as BuildHeaders
participant HTTP as HTTP Request
Note over Client,HTTP: Before: Token in DefaultHeaders (FAILED)
User->>Config: Create with ApiToken
activate Config
Config->>Client: new ApiClient(config)
activate Client
Client->>Client: DefaultHeaders.Add("Authorization", ...)
Client->>Config: Validate
activate Config
Config-->>Config: ❌ Reserved header in DefaultHeaders
Config-->>Client: Exception
deactivate Config
Client-->>User: Crash
deactivate Client
deactivate Config
Note over Client,HTTP: After: Token applied at request time (FIXED)
User->>Config: Create with ApiToken
activate Config
Config->>Client: new ApiClient(config)
activate Client
Client->>Config: Validate
activate Config
Config-->>Client: ✓ Valid (DefaultHeaders clean)
deactivate Config
Client-->>User: Success
deactivate Client
User->>Client: SendRequest
activate Client
Client->>Auth: GetAuthenticationTokenAsync
activate Auth
Auth-->>Client: Bearer token
deactivate Auth
Client->>Build: BuildHeaders(authToken)
activate Build
Build-->>Client: Merged headers<br/>(DefaultHeaders + Auth + Custom)
deactivate Build
Client->>HTTP: POST with Authorization header
HTTP-->>Client: Response
deactivate Client
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
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 |
ApiToken credentials no longer modify DefaultHeaders, avoiding reserved header validation error.
202d310 to
3d82885
Compare
Fix ApiToken reserved header exception
Fixes #146
Problem
Using
CredentialsMethod.ApiTokencaused the application to crash with: Header 'Authorization' is a reserved HTTP header and should not be set via custom headers.The issue: ApiToken was setting
AuthorizationinDefaultHeaders, which then failed validation as a reserved header.Solution
BuildHeaders()method instead ofDefaultHeadersGetAuthenticationTokenAsync()helperTesting
Impact
Summary by CodeRabbit