3

I am authenticated to github cli via token

gh auth status -h lalala.com
#=>
lalala.com
  ✓ Logged in to lalala.com as lolofon (~/.config/gh/hosts.yml)
  ✓ Git operations for lalala.com configured to use https protocol.

but, immediately executed afterwards:

gh pr list --repo lala/portal
#=>
HTTP 401: This endpoint requires you to be authenticated. (https://api.github.com/graphql)

What I am doing wrong? Thanks!

user_pruser
  • 422
  • 2
  • 13

2 Answers2

3

Apparently its a bug :-(
You can workaround it very easily by setting an env var like this:

set GH_HOST=lalala.com

See this GitHub issue for details

ShaulF
  • 841
  • 10
  • 17
0

See also PR 7449 which is now (May 2023) part of gh v2.30.0:

As an avid github.com Actions users, I spent several hours debugging 401 authentication failures that targeted a Github Enterprise Server (GHES) appliance.

I 100% saw the note that "if I was setting GH_ENTERPRISE_TOKEN then I should set GH_HOST". When I saw the auth failure for api.github.com I immediately knew I needed to set GH_HOST.

I had no idea that GH_TOKEN and GITHUB_TOKEN are disregarded if GH_HOST is not equal to either github or localhost.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250