rpcclient: make HTTP Basic Auth optional via DisableAuth#2514
Open
ThomsenDrake wants to merge 1 commit intobtcsuite:masterfrom
Open
rpcclient: make HTTP Basic Auth optional via DisableAuth#2514ThomsenDrake wants to merge 1 commit intobtcsuite:masterfrom
ThomsenDrake wants to merge 1 commit intobtcsuite:masterfrom
Conversation
Add a DisableAuth field to ConnConfig that, when set to true, skips setting the Authorization header on RPC requests. This enables connecting to third-party RPC providers (e.g. Alchemy, GetBlock) that authenticate via API key in the URL path and reject requests containing an Authorization header with 401 errors. Previously, getAuth() unconditionally set BasicAuth or attempted cookie auth, leaving no way to disable authentication entirely. Fixes btcsuite#2505
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.
Summary
Add a
DisableAuthfield toConnConfigthat, when set totrue, skips setting theAuthorizationheader on RPC requests (both HTTP POST and WebSocket modes).Problem
Currently,
handleSendPostMessageunconditionally callsgetAuth()andSetBasicAuth(). ThegetAuth()function has no "no auth" path — ifPassis empty, it falls through toretrieveCookie()which fails ifCookiePathis also empty.This makes it impossible to use
rpcclientwith third-party RPC providers (e.g. Alchemy, GetBlock) that:https://provider.com/v2/<api-key>)Authorizationheader with 401 errorsSolution
DisableAuth boolfield toConnConfigDisableAuthis true, skip thegetAuth()+SetBasicAuth()call in bothhandleSendPostMessage(HTTP POST mode) andnewHTTPClient(WebSocket mode)DisableAuthis false (default)Testing
go build ./rpcclient/...— clean buildgo test ./rpcclient/...— all tests passFixes #2505