Skip to content

rpcclient: make HTTP Basic Auth optional via DisableAuth#2514

Open
ThomsenDrake wants to merge 1 commit intobtcsuite:masterfrom
ThomsenDrake:rpcclient-disable-auth
Open

rpcclient: make HTTP Basic Auth optional via DisableAuth#2514
ThomsenDrake wants to merge 1 commit intobtcsuite:masterfrom
ThomsenDrake:rpcclient-disable-auth

Conversation

@ThomsenDrake
Copy link
Copy Markdown

Summary

Add a DisableAuth field to ConnConfig that, when set to true, skips setting the Authorization header on RPC requests (both HTTP POST and WebSocket modes).

Problem

Currently, handleSendPostMessage unconditionally calls getAuth() and SetBasicAuth(). The getAuth() function has no "no auth" path — if Pass is empty, it falls through to retrieveCookie() which fails if CookiePath is also empty.

This makes it impossible to use rpcclient with third-party RPC providers (e.g. Alchemy, GetBlock) that:

  • Authenticate via API key in the URL path (https://provider.com/v2/<api-key>)
  • Reject any Authorization header with 401 errors

Solution

  • Add DisableAuth bool field to ConnConfig
  • When DisableAuth is true, skip the getAuth() + SetBasicAuth() call in both handleSendPostMessage (HTTP POST mode) and newHTTPClient (WebSocket mode)
  • Existing behavior is unchanged when DisableAuth is false (default)

Testing

  • go build ./rpcclient/... — clean build
  • go test ./rpcclient/... — all tests pass

Fixes #2505

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rpcclient: make HTTP Basic Auth optional in HTTPPostMode

1 participant