Skip to content

feat: Add GH_AUTH_SCHEME environment variable for Bearer token support - #11726

Closed
nishithsoni wants to merge 1 commit into
cli:trunkfrom
nishithsoni:feature/bearer-auth-scheme
Closed

nishithsoni wants to merge 1 commit into
cli:trunkfrom
nishithsoni:feature/bearer-auth-scheme

Conversation

@nishithsoni

Copy link
Copy Markdown

Summary

  • Add support for GH_AUTH_SCHEME environment variable in AddAuthTokenHeader
  • Defaults to 'token' for backward compatibility
  • Set to 'Bearer' to use Bearer token authentication format
  • Add comprehensive tests for different auth schemes
  • Update environment variables documentation

This allows users to customize the authentication scheme used in
Authorization headers for all internal GitHub CLI API calls.

Related to issue: https://github.com/githubcustomers/Uber/issues/69

Customer Support thread: https://support.github.com/ticket/personal/0/3739042
Customer Reliability Engineer stated they would open a feature request that references your policy requirement. But I do not have the feature request link.

They also mentioned that other customers have run into this issue before and have had to create a proxy for this specific auth issue. I would prefer not to do that if it is a common pitfall of the CLI and would rather solve the issue with a change upstream.

This is a backwards compatible change to support the current default (Authorization: token) while adding support for Authorization: Bearer scheme auth which is required for JWT auth with GitHub APIs as referenced in GitHub docs here: https://docs.github.com/en/rest/authentication/authenticating-to-the-rest-api?apiVersion=2022-11-28

Test Plan

  • Added unit test coverage
  • Tested with a local install
$ gh --version
gh version 2.78.0-61-ga08fa994d (2025-09-12)
https://github.com/cli/cli/releases/latest
$ GH_AUTH_SCHEME="" GH_DEBUG=api gh pr create
[git remote -v]
[git config --get-regexp ^remote\..*\.gh-resolved$]
* Request at 2025-09-12 10:08:51.566744 -0700 PDT m=+0.833645209
* Request to https://github.uberinternal.com/api/graphql
> POST /api/graphql HTTP/1.1
> Host: github.uberinternal.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: token ████████████████████
> Content-Length: 407
> Content-Type: application/json; charset=utf-8
> Graphql-Features: merge_queue
> Time-Zone: America/Los_Angeles
> User-Agent: GitHub CLI v2.78.0-61-ga08fa994d
$ GH_AUTH_SCHEME=Bearer GH_DEBUG=api gh pr create
[git remote -v]
[git config --get-regexp ^remote\..*\.gh-resolved$]
* Request at 2025-09-12 10:20:25.852278 -0700 PDT m=+0.848363917
* Request to https://github.uberinternal.com/api/graphql
> POST /api/graphql HTTP/1.1
> Host: github.uberinternal.com
> Accept: application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview
> Authorization: Bearer ████████████████████
> Content-Length: 407
> Content-Type: application/json; charset=utf-8
> Graphql-Features: merge_queue
> Time-Zone: America/Los_Angeles
> User-Agent: GitHub CLI v2.78.0-61-ga08fa994d

- Add support for GH_AUTH_SCHEME environment variable in AddAuthTokenHeader
- Defaults to 'token' for backward compatibility
- Set to 'Bearer' to use Bearer token authentication format
- Add comprehensive tests for different auth schemes
- Update environment variables documentation

This allows users to customize the authentication scheme used in
Authorization headers for all internal GitHub CLI API calls.
@nishithsoni
nishithsoni requested a review from a team as a code owner September 12, 2025 17:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Add support for configurable authentication schemes in GitHub CLI by introducing the GH_AUTH_SCHEME environment variable, enabling Bearer token authentication for JWT-based auth requirements while maintaining backward compatibility.

  • Introduces GH_AUTH_SCHEME environment variable to customize the authentication scheme used in Authorization headers
  • Defaults to "token" scheme for backward compatibility, with support for "Bearer" and custom schemes
  • Adds comprehensive test coverage for different authentication schemes

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
api/http_client.go Implements the core logic to read GH_AUTH_SCHEME environment variable and apply custom auth scheme
api/http_client_test.go Adds comprehensive test coverage for different auth schemes including default, Bearer, and custom schemes
pkg/cmd/root/help_topic.go Updates environment variables documentation to describe the new GH_AUTH_SCHEME option

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@cliAutomation cliAutomation added the external pull request originating outside of the CLI core team label Sep 12, 2025
@BagToad

BagToad commented Sep 12, 2025

Copy link
Copy Markdown
Member

Hi @nishithsoni, thanks again for your efforts and work to improve gh for everyone ✨

As I mentioned in your other PR in #11667 (comment), we do not accept major contributions without an issue that has been discussed by our core maintainer team and subsequently had the help wanted Contributions welcome label added to it. Because of this, I'll close out this PR as well.

To move your request forward:

Please open an issue in our repository describing the why behind your request including what problems you're running into with the current behavior. We haven't heard this request from other users, so we really need much more detail about the problems and why you believe this will fix it, before adding any new settings.

After we have discussed the issue, and if we have labelled the issue as help wanted Contributions welcome , then you are welcome to contribute through a PR.

Reference:

This branch was previously deployed

1 inactive deployment
cli-automation — a08fa994 Deployed Sep 12, 2025 by nishithsoni
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants