usethis with GitHub Enterprise: Error: GitHub "auth_token" is invalid

I am having issues verifying a PAT while using GitHub enterprise. I have the PAT stored in a GITHUB_PAT environment variable.

# host replaced with enterprise name
use_github(host = "https://github.hostname.com/api/v3")

# > Error: GitHub `auth_token` is invalid.
# > See `browse_github_token()` for help storing a token as an environment variable.

Using traceback() and debugging, I see the error stems from usethis:::check_github_token(auth_token) and a call to gh::gh_whoami(auth_token) that is returning an error.

When I explicitly use gh::gh_whoami(.api_url = "https://github.hostname.com/api/v3") it returns a list as expected like this:

{
  "name": "Greg",
  "login": "USERNAME",
  "html_url": "https://github.hostname.com/USERNAME",
  "scopes": "gist, repo",
  "token": "2d..."
} 

I can't seem to figure out the proper way to pass my host URL so that the check for my GitHub token passes successfully.

If anyone has insight into what is going on it would be greatly appreciated!

Thanks,

Greg

When I've seen that error, it was because I didn't have my GitHub token in .Renviron. Like this:

.GITHUB_PAT='{your token}'

Do you mean to store an environment variable .GITHUB_PAT with the '.'?

I already have a GITHUB_PAT variable that returns correctly from:

Sys.getenv("GITHUB_PAT")

# > [1] "2d..."

Yes, that's what I was referring to. That '.' I put at the beginning was a typo.

Hi,

I have the exact same issue and 2 hours of online research did not help ...
If anyone can help that'd be awesome!

Grtz

Hi,

I think I figured out what's wrong, and might have found a solution, although I'm not sure...
I opened an issue on the package's github page with my proposed solution, so let's see if they can fix it

Grtz

That's great! I didn't dig into it too much, but I'm hopefull that it will address the problem.

Someone fixed it!

Apparently all you need to do is the following:

Sys.setenv(GITHUB_API_URL=<enterprise api url>)

And then run the use_github() :slight_smile:

See the gitHub issue link linked above for details

Grtz,
PJ