fix(gateway): inject Anthropic OAuth tokens correctly to resolve credential_not_found - #487
Open
Adityakk9031 wants to merge 1 commit into
Open
fix(gateway): inject Anthropic OAuth tokens correctly to resolve credential_not_found#487Adityakk9031 wants to merge 1 commit into
Adityakk9031 wants to merge 1 commit into
Conversation
Fixes onecli#482 **Description** Resolves an issue where Anthropic OAuth tokens (`sk-ant-oat...`) granted via the agent-grants UI failed to inject, resulting in a `401 credential_not_found` error from the Gateway. **Root Cause** The injection logic for Anthropic OAuth tokens mistakenly used `Injection::ReplaceHeader` to inject the `authorization` header. `ReplaceHeader` only applies if the header is already present in the incoming request. Since Claude Code or a bare `curl` typically sends `x-api-key: placeholder` and omits the `authorization` header, the injection was skipped (`injection_count == 0`). This caused the Gateway to forward the request unauthenticated and return `credential_not_found` when it inevitably received a 401 from Anthropic. **Changes** - Switched to `Injection::SetHeader` for the `authorization` token to ensure it is always injected. - Added `Injection::RemoveHeader` for `x-api-key` to strip the placeholder from the request before forwarding it upstream. - Updated the `build_injections_anthropic_oauth` unit test in `secret_inject.rs` to assert the new injection behavior.
Contributor
Author
|
@guyb1 have a look |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #482
Description
Resolves an issue where Anthropic OAuth tokens (
sk-ant-oat...) granted via the agent-grants UI failed to inject, resulting in a401 credential_not_founderror from the Gateway.Root Cause
The injection logic for Anthropic OAuth tokens mistakenly used
Injection::ReplaceHeaderto inject theauthorizationheader.ReplaceHeaderonly applies if the header is already present in the incoming request. Since Claude Code or a barecurltypically sendsx-api-key: placeholderand omits theauthorizationheader, the injection was skipped (injection_count == 0). This caused the Gateway to forward the request unauthenticated and returncredential_not_foundwhen it inevitably received a 401 from Anthropic.Changes
Injection::SetHeaderfor theauthorizationtoken to ensure it is always injected.Injection::RemoveHeaderforx-api-keyto strip the placeholder from the request before forwarding it upstream.build_injections_anthropic_oauthunit test insecret_inject.rsto assert the new injection behavior.