feat(webfetch): add RFC 9728 auth flow and harden OAuth handling#22096
Draft
irvinebroque wants to merge 2 commits intoanomalyco:devfrom
Draft
feat(webfetch): add RFC 9728 auth flow and harden OAuth handling#22096irvinebroque wants to merge 2 commits intoanomalyco:devfrom
irvinebroque wants to merge 2 commits intoanomalyco:devfrom
Conversation
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.
Issue for this PR
Closes #22095
Type of change
What does this PR do?
This PR adds OAuth-based authentication to
webfetch.Note — not at all wedded to the implementation — totally fine if maintainers want to discard it and start over. Have tried to keep it conformant with the style of the Opencode codebase, and minimally invasive as I could. But this does add quite a lot.
When
webfetchhits a protected resource, it can now:WWW-Authenticateopencode runredirect: "error"to avoid forwarding credentials to redirect targetsIt also adds a dedicated
webfetch_authpermission, documents the new auth module, extends the auth timeout so MFA / OTP / device flows do not inherit the normal short fetch timeout, and surfaces the auth UX in the TUI, desktop app, ACP, and headlessrunmode.Problem
webfetchcan fetch public URLs, but it had no way to complete standards-based OAuth discovery and authentication for protected resources. A 401/403 response would just fail, even when the server advertised an RFC-compliant auth path.There was also no clear policy for non-interactive environments. A browser-first flow is the best default for interactive clients, but
opencode runneeds a deterministic device-code path, and the implementation should not guess that from environment variables.What Changed
New auth module
Added a new
packages/opencode/src/auth/webfetch auth module.Considered trying to reuse bits that already exist — but seemed invasive and there wasn't a clear existing abstraction I found in opencode to build off. Could imagine the pieces below either being replaced by using another library, or refactored into a shared implementation.
webfetchintegrationUpdated
packages/opencode/src/tool/webfetch.tsto:WWW-AuthenticateUser-Agent: opencodeHow did you verify your code works?
Tested (mostly with TUI) giving OpenCode URLs that are protected by OAuth, and ensuring that the flow works end-to-end. Still need to do more to test the Desktop app and headless modes.
Screenshots / recordings
Checklist