hub: hub complains "Unauthorized (HTTP 401)" and "Bad credentials"
hub 2.2.2 on OS X complains “Unauthorized (HTTP 401)” and “Bad credentials” when I try to check out a pull request.
I have not used hub before. My credentials work in curl and on the web site. I have nothing in any OS X keychain matching “github”. My usual github access uses an SSH key and no 2FA.
% hub --version
git version 2.6.3 (Apple Git-62)
hub version 2.2.2
% ls ~/.config/hub
ls: /Volumes/precious/gparker/.config/hub: No such file or directory
[note git is not an alias, so the following is real git and not hub]
% git clone git@github.com:/apple/swift.git
Cloning into 'swift'...
remote: Counting objects: 318893, done.
remote: Compressing objects: 100% (123/123), done.
remote: Total 318893 (delta 42), reused 1 (delta 1), pack-reused 318768
Receiving objects: 100% (318893/318893), 66.27 MiB | 4.56 MiB/s, done.
Resolving deltas: 100% (261489/261489), done.
Checking connectivity... done.
Checking out files: 100% (9920/9920), done.
% cd swift
% env HUB_VERBOSE=1 hub checkout http://github.com/apple/swift/pull/862
github.com username: gparker42
github.com password for gparker42 (never stored):
> GET https://api.github.com/repos/apple/swift/pulls/862
> Authorization: token
< HTTP 401
{"message":"Bad credentials","documentation_url":"https://developer.github.com/v3"}
Error getting pull request: Unauthorized (HTTP 401)
Bad credentials
[note that I don’t have anything in ~/.config/hub after this sequence]
% curl -u gparker42 https://api.github.com/repos/apple/swift/pulls/862
Enter host password for user 'gparker42':
{
"url": "https://api.github.com/repos/apple/swift/pulls/862",
"id": 54923914,
"html_url": "https://github.com/apple/swift/pull/862",
[…]
About this issue
- Original URL
- State: open
- Created 8 years ago
- Reactions: 10
- Comments: 68 (32 by maintainers)
Nevermind: After removing
$HOME/.config/hubit works. It asked my user/pass and stored a new token. I expected it to be found in$HOME/.gitconfigbecause there I removed it the first time.I had this same problem. Turns out I had set GITHUB_TOKEN in my .zshrc long ago, to a token that was no longer valid. Removing this fixed the issue.
I’m sorry everyone for the bad experience. Hub error messaging should be more helpful in terms of what exactly failed and how to fix it.
The best course of action would be to completely refresh your credentials. To do that:
echo $GITHUB_TOKEN;repoandgistscopes;~/.config/huband paste the following:It works for me after updating the
oauth_tokenvalue within~/.config/hubRegenerate your token at: https://github.com/settings/tokens/ Open the config file as
vim ~/.config/hubPaste your generated token like the following: oauth_token: PASTE_HERENow you can use:
hub createI just ran into this issue. The fix was:
There was some strange code there, perhaps an old token from a late night code binge. It was wrong. Set the correct access token (created in Github Settings) making the file look like:
No, that doesn’t work. Hub needs to access the GitHub API over HTTPS and that has nothing to do with git push/pull protocol (which is ssh for you).
You can generate a Personal Access token from your user settings and manually configure hub to use it. Create a
~/.config/hubfile with:Note that “protocol” value here can only be
httpsorhttp, but notssh.@AndrewSB Thanks for all the info. That indeed looks like a bug.
If you run
HUB_VERBOSE=1 hub clone proxyco/consumer-ios, there will be more debugging info about HTTP requests for you to inspect. Maybe you will find something interesting. Just remember to strip away all the sensitive info (such as tokens) before pasting any of that information here.If you want to unblock yourself for now while we investigate this, you can generate a Personal Access Token from your settings online and paste it in a
~/.config/hubfile that you create:I’m still getting the 404 error here in 2020. I’ve tried all of above, and no luck
I solved the problem by running
hub pr list. This caused hub to prompt me for my username and password and then create an OAuth token on my behalf. After going to GitHub and enabling SSO, it’s working flawlessly!@pboling yes, and just like last time that worked. However this bug is about hub rejecting valid credentials.
If I put in my username and token, it should accept them, not throw a 401 until I put the same username and token into a config file.
Just wanted to drop a note that I was also getting this same HTTP Unauthorized error on macOS Sierra and hub version 2.2.9 installed via brew. Using
HUB_VERBOSEit looked like everything was going through correctly, and indeed github.com showed a new personal access token created, but hub was still showing the error and asking for my credentials every time I ran it. The fix for me was creating the~/.configdirectory manually (this is a pretty fresh install of Sierra and it didn’t exist) and then re-running hub.Yes, that does seem to work.
@maxandersen In the meantime, until hub implements re-authorization, can you just swap your token in
~/.config/hubwith the one that you pasted asGITHUB_TOKEN?Via the API? I’m not sure. We log into the website via an SSO front-door and do git operations via ssh. That might be the problem. Might want to add something to the docs about how to set up the ~/.config/hub file manually.