Gerg
June 26, 2019, 4:37pm
1
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
jimmy
June 26, 2019, 7:02pm
2
When I've seen that error, it was because I didn't have my GitHub token in .Renviron. Like this:
.GITHUB_PAT='{your token}'
Gerg
June 26, 2019, 7:06pm
3
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..."
jimmy
June 26, 2019, 7:09pm
4
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
1 Like
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
opened 03:36PM - 11 Jul 19 UTC
closed 08:48PM - 12 Jul 19 UTC
Hi,
I noticed that when trying to us the use_github() function with an enterp… rise account, it will give me an error saying
```
Error: GitHub `auth_token` is invalid.
See `browse_github_token()` for help storing a token as an environment variable.
```
After a long search I found out this is because I have an enterprise account through my university and it uses a different host address. When I do use the host api in the function (e.g. use_github(host = "github.uc.edu/api/v3") ), it still produces the same error.
I know the token is working as I tested it with the gh function:
```r
gh::gh_whoami(.api_url = "https://github.uc.edu/api/v3")
```
I dug in the code and think I found the source of the problem in the following function:
```r
github_user <- function(auth_token = github_token()) {
suppressMessages(
tryCatch(gh::gh_whoami(auth_token), error = function(e) NULL)
)
}
```
This will generate a NULL value if the correct host variable is not given. I think it can simply be fixed by adding the .api_url = host (where host is the variable specified in the use_github ) like so:
```r
github_user <- function(auth_token = github_token()) {
suppressMessages(
tryCatch(gh::gh_whoami(auth_token, .api_url = host), error = function(e) NULL)
)
}
```
Let me know what you think!
Grtz,
PJ
Grtz
Gerg
July 12, 2019, 12:13am
7
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()
See the gitHub issue link linked above for details
Grtz,
PJ
system
Closed
August 25, 2021, 12:15pm
9
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.