-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GitHub PAT error with https protocol: detects user GH password instead of the token #1347
Comments
This is the best set of instructions re: GitHub setup: https://usethis.r-lib.org/articles/articles/git-credentials.html There's a lot to read above, but upon skimming, it sound like at some point maybe someone was prompted for PAT = "personal access token", but provided a password instead? Hard for me to guess. GitHub is shutting down HTTPS access with a username+password, so anyone using HTTPS, which I recommend, absolutely needs to get a PAT and start using it anyway. |
Hi, Looking at this again, I think that r-lib/gitcreds#16 might have been related. There might be a git credential saved on her macOS Keychain Access with the incorrect info (password instead of PAT), which makes the issue hard to reproduce for me. Or maybe Ultimately, I was able to get the same error though, which I think can happen because the message by Once that has happened, the error message by If you want, I can send a PR. If you consider that it's out of scope for Best, DetailsI don't think that I've run In any case, I get on both macOS and Windows: > gitcreds::gitcreds_delete(url = "https://github.com")
> gitcreds::gitcreds_get(url = "https://github.com")
<gitcreds>
protocol: NA
host : NA
username: NA
password: <-- hidden -->
> nchar(gitcreds::gitcreds_get(url = "https://github.com")$password)
[1] 40 as in, I never see my GitHub username listed by If I run > options(usethis.protocol = "https")
> usethis::create_github_token()
* Call `gitcreds::gitcreds_set()` to register this token in the local Git credential store
It is also a great idea to store this token in any password-management software that you use
√ Opening URL 'https://github.com/settings/tokens/new?scopes=repo,user,gist,workflow&description=R:GITHUB_PAT' If I then follow the recommendation, I get > gitcreds::gitcreds_set()
? Enter password or token: 5efcc09fcc37da4f1935fdbb16e0fbf5c33f1d5d
-> Adding new credentials...
-> Removing credetials from cache...
-> Done.
## no worries, I've deleted that PAT from my GH account If I then check to see if my username will pop up, it doesn't. But that's because > gitcreds::gitcreds_get(url = "https://github.com")
<gitcreds>
protocol: NA
host : NA
username: NA
password: <-- hidden -->
> gitcreds::gitcreds_get(url = "https://github.com")$password
[1] "my_real_token (censored)" Then if I comment out my > gitcreds::gitcreds_get(url = "https://github.com")
<gitcreds>
protocol: https
host : github.com
path :
username: PersonalAccessToken
password: <-- hidden -->
> gitcreds::gitcreds_get(url = "https://github.com")$password
[1] "5efcc09fcc37da4f1935fdbb16e0fbf5c33f1d5d" I can then remove this information. > gitcreds::gitcreds_delete(url = "https://github.com")
-> Your current credentials for 'https://github.com':
protocol: https
host : github.com
path :
username: PersonalAccessToken
password: <-- hidden -->
-> What would you like to do?
1: Keep these credentials
2: Delete these credentials
3: See the password / token
Selection: 2
-> Removing current credentials...
-> Removing credetials from cache...
-> Done. If I then run the setter again with my real GitHub password, it goes through. Yet it thinks that I'm giving it a Personal Access Token (PAT). > gitcreds::gitcreds_set(url = "https://github.com")
? Enter password or token: my_real_github_password
-> Adding new credentials...
-> Removing credetials from cache...
-> Done.
> gitcreds::gitcreds_get(url = "https://github.com")
<gitcreds>
protocol: https
host : github.com
path :
username: PersonalAccessToken
password: <-- hidden -->
> gitcreds::gitcreds_get(url = "https://github.com")$password
[1] "my_real_github_password" At this point, I can then reproduce the error Louise was getting, although our > gh::gh_token(NULL)
Error in validate_gh_pat(new_gh_pat(x)) :
A GitHub PAT must consist of 40 hexadecimal digits So, like Jenny said earlier, maybe Louise typed her GitHub password instead of pasting the GitHub PAT. Yet once that happened, the error messages were very confusing. To restore my setup, I ran Hopefully this issue will help anyone running into this problem in the future. |
Ahh, now I see r-lib/gh#133. Interesting! |
I feel like this issue is muddying the waters. As I've tried to explain in this vignette: https://usethis.r-lib.org/articles/articles/git-credentials.html These are the recommendations:
If you follow those instructions, I don't think you encounter a problem. I specifically recommend against storing the PAT in a startup file. I think this was just a case of something incorrect being entered into the cache (a password instead of a PAT), then predictable downstream errors due to that. |
Thanks again Jenny! I just updated |
Hi,
Louise @lahuuki was setting up a new R package with
usethis
and we encountered a confusing error message that is really agh
error derived fromgitcreds
output.This issue gets resolved if you run (or edit your
~/.Rprofile
) with:which I had in my macOS but Louise didn't in her macOS setup.
Without those lines of code, Louise gets her GitHub password which is not 40 characters long.
while I indeed get my 40 characters long GitHub personal access token (PAT).
The help file at https://usethis.r-lib.org/reference/git_protocol.html doesn't seem to indicate that using a
https
protocol would be a problem. Looking at our~/.Rprofile
and~/.gitconfig
nothing seems to jump at me. Both of us have aGITHUB_PAT="40 characters long token"
entry in our~/.Renviron
.So, from the docs it seems to me that https is supported. I'm not sure if some specific configuration in Louise's setup is leading to the error, or if it's a change in the expected output from
gitcreds
inside thegh
code. In any case, I'm reporting the issue here such that otherusethis
users can locate the error and solution more quickly that we did.Best,
Leo
Session info:
The text was updated successfully, but these errors were encountered: