gh-copilot
gh-copilot copied to clipboard
[FEAT]: Allow personal access tokens to be used with `gh-copilot`
Thanks for taking the time to fill out this out! :bow: By submitting this issue, you agree to follow our Code of Conduct.
Describe the need
Users like @gr2m, @yermulnik and @dark-light-cz have run into problems using gh-copilot in https://github.com/github/gh-copilot/issues/1 and https://github.com/github/gh-copilot/issues/98 due to the use of personal access tokens. This is because gh-copilot has only supported the use of GitHub CLI OAuth app due to requirements of the Copilot platform.
This issue is track interest in extending support to personal access tokens.
Version
This affects all github/gh-copilot versions prior to v1.0.6 at the time of creating this issue.
Relevant terminal output
$ export GH_TOKEN="ghp_..."
$ gh copilot suggest
✗ Error: No valid GitHub CLI OAuth token detected
To get started with GitHub Copilot in the CLI, please run: gh auth login --web -h github.com to authenticate via web browser.
Just to bump this issue as of https://github.blog/changelog/2025-02-12-github-copilot-chat-and-github-copilot-extension-now-available-for-free-on-github-mobile-and-github-cli/ announcement: ain't gh-copilot should be capable of utilizing https://github.com/cli/go-gh (a collection of Go modules to make authoring GitHub CLI extensions easier) for auth to bring smoother experience to users? 🤔
@andyfeller By any chance is this issue on a development roadmap please? 🙏🏻
Just to bump this issue as of https://github.blog/changelog/2025-02-12-github-copilot-chat-and-github-copilot-extension-now-available-for-free-on-github-mobile-and-github-cli/ announcement: ain't
gh-copilotshould be capable of utilizing https://github.com/cli/go-gh (a collection of Go modules to make authoring GitHub CLI extensions easier) for auth to bring smoother experience to users? 🤔@andyfeller By any chance is this issue on a development roadmap please? 🙏🏻
Thanks for the bump, @yermulnik ❤
The good news is gh-copilot has used cli/go-gh since its inception! ✊ The bad news is that PAT restriction is a larger Copilot authentication challenge beyond gh-copilot. That said, let me see about following up internally to see if there's any movement there.
cc @RyanHecht
Ah, I see. Apologies my newbie mix up of the things =) And thanks for keeping this request rolling 👍🏻
I have run into the very same issue and would even consider the current behaviour as bug for two reasons
- The error message does not tell you that the copilot plugin is using the PAT from the environment but cannot authenticate with it (-> better error message)
- The plugin should simply ignore the PAT if it cannot use it for authentication (at most issue a warning).
However, in the end, I'd be happy with both solutions, i.e., if either authentication via PAT would be possible, or if the PAT would be ignored by the plugin (falling back to the next level of authentication).
@andyfeller You asked in some other thread why people use a PAT in environment variables for gh. I just wanted to note that we add PAT to shell environment variable GH_TOKEN, because of a Neovim plugin that uses gh under the hood. Saves us having to authenticate with a browser, each time nvim is opened.
Is there any way to keep that variable intact in the environment, and still access gh copilot? Perhaps setting another environment variable that takes precedence?
Thanks for the help.
What I did to solve my problema in my use case was:
- unset GITHUB_TOKEN and GH_TOKEN
- authenticated with 'gh auth login --web -h github.com'
- got the token with 'gh auth token -h githbu.com' (the token will start with "gho_")
- set the GH_TOKEN with this value. (I did put this in my startup script - .zshrc/.bashrc and $PROFILE for PowerShell)
- GH_TOKEN has precedence over GITHUB_TOKEN, so both can be set and the gh cli will use the GH_TOKEN.
- Now I can use the cli and keep my GITHUB_TOKEN for use in other scenarios.
I don't know if it is possible to use GITHUB_TOKEN with neovim's plugins.