Skip to content

Support Authorization: Bearer scheme for internal api calls #11727

Open

Description

@nishithsoni

Describe the feature or problem you’d like to solve

I am a customer at Uber. We would like to enable the GitHub CLI for our enterprise but are unable to do so because our internal proxy requires the Bearer scheme in the Authorization: headers for any api calls. This however is not supported by the GitHub CLI despite being noted in the API docs here.

I am unsure if the Bearer scheme works with all currently supported token forms using the Authorization: token scheme.

But if it would be possible to maintain backwards compatibility with the current token scheme while adding support for Bearer, it would greatly help.

Proposed solution

  • 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

PR with proposed solution: #11726

Additional context

https://github.com/githubcustomers/Uber/issues/69

https://support.github.com/ticket/personal/0/3739042

Activity

  1. added
    enhancement
    on Sep 12, 2025
  2. github-actions commented on Sep 12, 2025

    @github-actions
    Contributor

    Thank you for your issue! We have categorized it as a feature request, and it has been added to our backlog. In doing so, we are not committing to implementing this feature at this time, but, we will consider it for future releases based on community feedback and our own product roadmap.

    Unless you see the help wanted Contributions welcome label, we are not currently looking for external contributions for this feature.

    If you come across this issue and would like to see it implemented, please add a thumbs up! This will help us prioritize the feature. Please only comment if you have additional information or viewpoints to contribute.

  3. added
    needs-triage
    on Sep 12, 2025
  4. babakks commented on Sep 25, 2025

    @babakks
    Member

    Thanks for opening the issue, @nishithsoni! 🙏

    As you pointed out a big question is whether all API endpoints would work with the Bearer scheme. Maybe the answer is yes, but I'm not sure and this needs further investigation/comms.

    Also, even with Bearer for all requests, there are still special cases when the Authorization header is not applicable (e.g. when logging in). I'm not sure how your setup handles such cases (maybe it's just fine if there's no auth header, idk).

    Anyway, I'll keep this issue open since there's already some context to this.

  5. added
    needs-investigation
    auth
    core
    on Sep 25, 2025
  6. behinddwalls commented on Mar 4, 2026

    @behinddwalls

    As long as the Authorization header follows standard Bearer or Basic schemes, I don’t see an issue.

    For login flows, the CLI supports both PATs and OAuth tokens, which are typically passed as Bearer tokens and should be fine.

    For OAuth (both web and device flows), the token exchange appears to happen via a POST request with a payload to obtain the token, rather than relying on pre-existing Authorization headers. That also seems appropriate.

    That said, there could be edge cases or GitHub-specific behaviors that aren’t obvious from the CLI codebase alone.

    Ref.: https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps#device-flow

  7. williammartin commented on Mar 4, 2026

    @williammartin
    Member

    I'm just bringing across the context from #12828 into this issue because it's valuable.

    Describe the feature or problem you'd like to solve

    The GitHub CLI currently uses the token scheme for Authorization headers (Authorization: token <TOKEN>), while GitHub's official API documentation and examples consistently use the standard Bearer scheme (Authorization: Bearer <TOKEN>).

    This creates three problems:

    1. Blocks JWT/GitHub App authentication: GitHub's REST API documentation explicitly states: "if you are passing a JSON web token (JWT), you must use Authorization: Bearer". The current token scheme prevents proper GitHub App integration.

    2. Blocks enterprise proxy/SSO integrations: Many enterprises use proxy patterns where SSO issues internal bearer tokens, a proxy exchanges them for GitHub tokens via GitHub App authentication, and forwards requests to GitHub's API. The token scheme forces enterprises to build custom workarounds, maintain CLI forks, or avoid the CLI entirely because GitHub Apps expect Bearer per OAuth 2.0 standards.

    3. Diverges from GitHub's own standards: All official GitHub API curl examples use Bearer, and GitHub's own tools (Octokit, GitHub Actions) use Bearer as the standard. The CLI is inconsistent with the broader GitHub ecosystem.

    Proposed solution

    Change all Authorization headers from token scheme to Bearer scheme:

    Current:

    req.Header.Set(authorization, fmt.Sprintf("token %s", token))

    Proposed:

    req.Header.Set(authorization, fmt.Sprintf("Bearer %s", token))

    Benefits:

    • Enables JWT-based GitHub App authentication
    • Removes barriers for enterprise proxy/SSO integrations
    • Aligns with GitHub's documented API standards and examples
    • Complies with RFC 6750 (OAuth 2.0 Bearer Token Usage)
    • Matches GitHub's own tooling ecosystem (Octokit, Actions, etc.)
    • Future-proofs the CLI as GitHub continues OAuth 2.0 standardization

    Compatibility: According to GitHub's documentation, both schemes are currently accepted for personal access tokens, so this change is non-breaking for individual users while unlocking enterprise and GitHub App scenarios.

    Files affected:

    • api/http_client.go
    • pkg/cmd/auth/shared/login_flow.go
    • pkg/cmd/auth/shared/oauth_scopes.go
    • Associated test files

    Additional context

    This issue is related to closed PR #11667 by @nishithsoni, which was closed pending proper justification per contribution guidelines.

    References:

  8. williammartin commented on Mar 4, 2026

    @williammartin
    Member

    Responding to the individual points:

    Blocks JWT/GitHub App authentication: GitHub's REST API documentation explicitly states: "if you are passing a JSON web token (JWT), you must use Authorization: Bearer". The current token scheme prevents proper GitHub App integration.

    We don't really intend for gh to support JWT authentication out of the box. As far as I'm aware, the number of endpoints that accept JWTs are very small, and primarily related to managing installation tokens (which are supported) so effectively it would only be relevant for custom gh api commands, which allow headers to be overridden anyway. Every other command would be broken.

    Blocks enterprise proxy/SSO integrations: Many enterprises use proxy patterns where SSO issues internal bearer tokens, a proxy exchanges them for GitHub tokens via GitHub App authentication, and forwards requests to GitHub's API. The token scheme forces enterprises to build custom workarounds, maintain CLI forks, or avoid the CLI entirely because GitHub Apps expect Bearer per OAuth 2.0 standards.

    I think it's fair for us to find a solution in gh, but it's not clear to me how big a blocker this is for proxies. Is the issue that you don't want to build logic into your proxy to sometimes look for Authorization: token ... to get the internal Bearer token for exchange?

    I'm currently waiting to get access to those internal tickets linked in the original description.

    Diverges from GitHub's own standards: All official GitHub API curl examples use Bearer, and GitHub's own tools (Octokit, GitHub Actions) use Bearer as the standard. The CLI is inconsistent with the broader GitHub ecosystem.

    Sort of true? Octokit uses token unless a JWT is being passed. Actions is a bit too broad for me to know exactly what you are referring to. I do agree with the docs point though, and that's probably the most salient.

    Change all Authorization headers from token scheme to Bearer scheme:

    Between the CLI and the API, I don't think there's much of a risk in this change. However, I am concerned that if we make this change we'll run into the opposite problem, where proxies might be expecting Authorization headers of the current format, since it has been that way for many years.

    Let's keep this issue moving and get this resolved for y'all. Do you use gh CLI extensions at all? One thing that comes to mind is that the previously closed PR would only adjust the token scheme for gh, but not extensions built using go-gh: https://github.com/cli/go-gh/blob/55692c6b904c06e3c01870fa81b326c2d0c88123/pkg/api/http_client.go#L182

  9. behinddwalls commented on Mar 4, 2026

    @behinddwalls

    Digging deeper into the Proxy/SSO flow and how it works for us today:

    Proxy Behavior

    Our proxy layer (Envoy/Nginx) is fairly simple. It accepts an Authorization header with only two supported schemes:

    • Bearer
    • Basic

    Any other token type (e.g., Authorization: token ...) is not recognized and will be rejected.

    SSO Flow

    • The user completes MFA authentication in the browser.
    • The device that initiated SSO receives an SSO token (Bearer), valid for a limited duration (e.g., ~24 hours).
    • This SSO Bearer token is sent to the Nginx/Envoy proxy.
    • The proxy authenticates the user and forwards the request to a GitHub aware proxy.
    • The GitHub aware proxy performs a token exchange:
      • It maps the authenticated SSO identity to a GitHub App user token.
      • This works only if the user has previously authorized the GitHub App (Prerequisite for user).

    CLI Integration

    In our setup:

    • We provide a wrapper around the gh CLI to abstract SSO details and configure the host appropriately.
    • From our perspective, gh CLI can only operate using a Bearer token.
    • There is no support for other token schemes in our flow.

    Therefore, using an Authorization header of type token (instead of Bearer) will not work, since the Envoy/Nginx proxy does not recognize that scheme. Given it's global proxy for the whole company, we don't really have much control to say add token scheme into that layer for us to use it as Bearer token.

    I wonder if we could use Bearer behind some feature flag that we could enable in host configuration?

    @nishithsoni feel free to add additional details on CLI wrapper set-up and how we plan to configure underlying Auth/Configs for gh CLI.

    Let's keep this issue moving and get this resolved for y'all. Do you use gh CLI extensions at all? One thing that comes to mind is that the previously closed PR would only adjust the token scheme for gh, but not extensions built using go-gh: https://github.com/cli/go-gh/blob/55692c6b904c06e3c01870fa81b326c2d0c88123/pkg/api/http_client.go#L182

    I think folks may want to use it internally, so likely down the line someone will ask for them. @nishithsoni what's our plan here? Are we enabling them?

  10. nishithsoni commented on Mar 4, 2026

    @nishithsoni
    Author

    we'll run into the opposite problem, where proxies might be expecting Authorization headers of the current format, since it has been that way for many years.

    @williammartin @behinddwalls In order to keep this backwards compatible and not introduce any breaking changes, I had implemented the change behind a built-in envvar (i.e. GH_USE_BEARER_AUTH=1) similar to a feature flag.

    If there isn't much of a risk with the change and would still support existing token types, I see no reason that we cannot to add this Bearer token support.

    I think folks may want to use it internally, so likely down the line someone will ask for them. @nishithsoni what's our plan here? Are we enabling them?

    Hadn't given extensions much thought but this would also require Bearer Auth scheme. We may be able to disable it as a last resort, but I'd like to support extensions as long as there is no other blockers.
    This will also give us the extensibility of developing our own extensions on top of GH or giving other internal users the ability to build on top of the platform.

  11. removed
    needs-triage
    on Mar 11, 2026
  12. nishithsoni commented on May 8, 2026

    @nishithsoni
    Author

    This change also needs to be in the go-gh library that is used by gh extensions such as gh stack. Being able to make the same change in gh-cli and go-gh would be ideal.

    https://github.com/cli/go-gh/blob/55692c6b904c06e3c01870fa81b326c2d0c88123/pkg/api/http_client.go#L182

  13. removed
    needs-investigation
    on May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    authcoreenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions