Add bearer_auth config toggle for Authorization scheme#13400
Add bearer_auth config toggle for Authorization scheme#13400williammartin wants to merge 11 commits into
bearer_auth config toggle for Authorization scheme#13400Conversation
340416f to
937d129
Compare
There was a problem hiding this comment.
Pull request overview
Adds a new configuration toggle (bearer_auth) and env var (GH_BEARER_AUTH) to control whether gh uses Authorization: token … (default) or Authorization: Bearer … when attaching auth tokens to HTTP requests, including during login/refresh/status flows.
Changes:
- Introduces
bearer_authconfig option (per-host) andAuthConfig.BearerAuth(host)resolution (env var override + config lookup). - Updates auth-related HTTP requests and transports to emit
Bearerwhen enabled, and threads the toggle through login, refresh, status, and OAuth viewer verification. - Expands tests to cover config/env resolution and Authorization header behavior.
Show a summary per file
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Files not reviewed (1)
- internal/gh/mock/config.go: Language not supported
- Files reviewed: 17/18 changed files
- Comments generated: 1
1734423 to
6e63141
Compare
| type tokenGetter interface { | ||
| ActiveToken(string) (string, string) | ||
| } | ||
| type getTokenFunc func(string) (string, string) |
There was a problem hiding this comment.
This is cleaning up some code that had obviously become stale when the config used to be provided here.
There was a problem hiding this comment.
This could be used in other places and should have a follow up PR. It's repeated a few times around the codebase.
There was a problem hiding this comment.
I also suspect it should maybe go into go-gh to form a consistent basis for any extensions too, but that can be a follow up.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove BearerAuth(hostname string) bool from the AuthConfig interface and implementation. Bearer auth is a general config setting, not an auth-domain concern, so it belongs on Config alongside other settings like browser, editor, and git_protocol. Update cfg.BearerAuth to check the GH_BEARER_AUTH environment variable first, returning a new ConfigEnvironmentProvided source, before falling back to the standard GetOrDefault config resolution. Split the tokenGetter interface in api/http_client.go so it only contains ActiveToken. Bearer auth is now passed as a separate function via HTTPClientOptions.BearerAuth, with nil-safety defaulting to false. Add an acceptance test verifying that GH_DEBUG=api output shows the correct auth scheme (token vs Bearer) based on GH_BEARER_AUTH. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace tokenGetter interface with getTokenFunc in HTTPClientOptions - Replace BearerAuth func(string) bool with GetBearerConfig gh.ConfigGetter - Move GH_BEARER_AUTH env var check to shouldUseBearerAuth in api package - Remove unused notice parameter from AuthFlow - Add ConfigGetter type and remove ConfigEnvironmentProvided source Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Replace tinyConfig map type with stubGetToken helper function - Add disabledBearerConfig for test defaults - Remove nil guard on getBearerConfig in shouldUseBearerAuth - All callers now explicitly provide GetBearerConfig Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Export ShouldUseBearerAuth to centralize env var and config checks - Change GetScopes, HasMinimumScopes, GetCurrentLogin to take gh.ConfigGetter - Replace authTokenHeader with authScheme using api.ShouldUseBearerAuth - Update status.go buildEntryOptions to use gh.ConfigGetter - Add acceptance test for auth status with GH_BEARER_AUTH Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add factory HTTP client coverage via gh repo view. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
If getBearerConfig is not provided, default to disabled rather than panicking with a nil pointer dereference. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
f2c666b to
f4b6e8a
Compare

Description
Fixes #11727
Adds a
bearer_authconfig setting andGH_BEARER_AUTHenvironment variable to control the Authorization header scheme used in HTTP requests.When enabled,
Authorization: token <TOKEN>becomesAuthorization: Bearer <TOKEN>.Acceptance Test
Companion PR
The corresponding
go-ghchanges for extension support: cli/go-gh#222