github / gh-copilot

Ask for assistance right in your terminal.
https://docs.github.com/en/copilot/github-copilot-in-the-cli
760 stars 31 forks source link

[BUG]: gh copilot authentication not working with access token in environment variable #98

Open dark-light-cz opened 1 month ago

dark-light-cz commented 1 month ago

Issue description

When setting ENV variable for access token authentication for gh it works, but extension is not authenticated and keeps asking for login.

Versions

gh version 2.57.0 (2024-09-16) gh copilot github/gh-copilot v1.0.5

Relevant terminal output

ENV: setting:

GITHUB_USER=dark-light-cz
GH_DEBUG=1
GITHUB_TOKEN=ghp_********************
GITHUB_COPILOT_TOKEN=ghp_********************

gh auth check

* Request at 2024-09-18 12:13:20.19324395 +0200 CEST m=+0.105356241
* Request to https://api.github.com/graphql
* Request took 316.430817ms
* Request at 2024-09-18 12:13:20.510053279 +0200 CEST m=+0.422165570
* Request to https://api.github.com/
* Request took 166.098938ms
github.com
  ✓ Logged in to github.com account dark-light-cz (GITHUB_TOKEN)
  - Active account: true
  - Git operations protocol: https
  - Token: ghp_************************************
  - Token scopes: 'admin:enterprise', 'admin:gpg_key', 'admin:org', 'admin:org_hook', 'admin:public_key', 'admin:repo_hook', 'admin:ssh_signing_key', 'audit_log', 'codespace', 'copilot', 'delete:packages', 'delete_repo', 'gist', 'notifications', 'project', 'repo', 'user', 'workflow', 'write:discussion', 'write:packages'

ghcs call

* Request at 2024-09-18 12:13:24.818749857 +0200 CEST m=+0.613217910
* Request to https://api.github.com/graphql
* Request took 283.78844ms

✗ 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.
williammartin commented 1 month ago

Hey @dark-light-cz, thanks for creating the issue and sorry you're having issues.

I can't see anything obviously wrong with what you are doing but I do have one hunch. Can you share how you installed gh? Can you share the exact command you used when you ran gh auth status e.g. was it ./gh auth status? Basically I'd like to understand if gh is on your PATH, perhaps you can check with which gh?

dark-light-cz commented 1 month ago

Hi I'm on debian11

gh is installed from oficial repository deb [arch=amd64 signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main using apt install gh and copilot installed gh extension install github/gh-copilot

~$ apt-cache policy gh
gh:
  Installed: 2.57.0
  Candidate: 2.57.0
  Version table:
 *** 2.57.0 500
        500 https://cli.github.com/packages stable/main amd64 Packages
        100 /var/lib/dpkg/status

gh is used from /bin/

~$ which gh
/bin/gh
williammartin commented 1 month ago

Alright, when I have a moment I'll see if I can reproduce this. Is there any other information you think might be useful for investigation? Did this ever work? Did it work when you weren't using the env var but maybe using gh auth login?

dark-light-cz commented 1 month ago

It's the first time I'm trying to authenticate cli throuh env variable, so I don't know if it woked before.

It works well if I login using suggested gh auth login --web -h github.com.

Thank you for your help.

williammartin commented 1 month ago

Ok that's good to know. I haven't looked into how extensions work with environment variable auth before, so I'll have a look at that later. Thanks for the hints.