Skip to content
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

hub fork fails when GHE returns 404 #660

Closed
nikreiman opened this issue Oct 22, 2014 · 26 comments · Fixed by #669
Closed

hub fork fails when GHE returns 404 #660

nikreiman opened this issue Oct 22, 2014 · 26 comments · Fixed by #669

Comments

@nikreiman
Copy link

When I try to fork a repo which is located on a GHE server, I get an error message "No decoder found for format (text/html; charset=utf-8)". I've built hub from source from master, and its version reports git version 1.9.1 (repo hash is 456adff).

Updates from #660 (comment): while the authentication problem was fixed in #669, GHE returns 404 for hub fork:

master u=!po-test> HUB_VERBOSE=1 hub fork
> GET https://ghe.mycompany.net/api/v3/repos/nik/test
> Authorization: token [REDACTED]
< HTTP 404
{"message":"Not Found","documentation_url":"https://developer.github.com/v3"}
> POST https://ghe.mycompany.net/api/v3/repos/po/test/forks
> Authorization: token [REDACTED]
< HTTP 404
{"message":"Not Found","documentation_url":"https://developer.github.com/v3"}
master u=!po-test> git remote -v show
origin  [email protected]:po/test.git (fetch)
origin  [email protected]:po/test.git (push)
master u=!po-test> hub --version
git version 1.9.1
hub version 2.2.0-preview1
@owenthereal
Copy link
Contributor

@nikreiman Do you mind sharing the stacktrace if there's any?

@owenthereal
Copy link
Contributor

This is related to go-sawyer can't find the decoder for media type. Only JSON and XML are supported. Not sure why GHE is returning text/html instead. Need more debug info. Besides pasting the stacktrace here, could you try:

$ HUB_VERBOSE=true hub fork

Hopefully it will at least print out the request/response without crashing.

@nikreiman
Copy link
Author

Hmm looking at the output, it seems that I get an HTML webpage redirecting to the login. So it's probably caused by 2-factor auth, which we do have in place in our GHE instance.

I see that 2FA is supported (was fixed in #399), but I have no idea how to configure it. It's not documented anywhere.

@owenthereal
Copy link
Contributor

@nikreiman It's enabled by default. When you login, hub will prompt for 2FA code if the server enables it. You could remove ~/.config/hub and trigger the login process again. But if hub has already received a valid oauth token, you shouldn't need to re-login. Have you been using hub before, say for version 1.x?

@nikreiman
Copy link
Author

@jingweno yes, I was using hub 1.x from apt-get, but had problems with it and am now using one I built myself from the repo. As for ~/.config/hub, that file seems not to exist. Does it go somewhere else on Linux?

@mislav
Copy link
Owner

mislav commented Oct 24, 2014

@nikreiman If ~/.config/hub doesn't exist, that means you never authenticated either against github.com or your own GHE instance.

First of all, have you followed the instructions from the man page (also available online) to whitelist your GHE hostname for hub?

Second, does hub prompt you for username/password when you run hub fork? Is the authentication successful? Does it ever ask for 2FA token?

@nikreiman
Copy link
Author

@mislav I've followed the instructions from the docs, my ~/.gitconfig has this section in it

[hub]
  host = ghe.mycompany.net
  protocol = https
  user = nik
  email = [email protected]
  token =  "5dc3NOTMYREALTOKENe5e"

When I attempt to run hub fork I get the following output:

master u=!po-test> hub fork
github.com username: nik
ghe.mycompany.net password for nik (never stored): 
No decoder found for format  (text/html; charset=utf-8)

So no, I'm never prompted for the 2FA token. A colleague of mine mentioned that I could manually set the token from GHE's apps page and put it in the ~/.gitconfig, which I tried (unsuccessfully).

@mislav
Copy link
Owner

mislav commented Oct 28, 2014

@nikreiman hub.user/email/token config lines are never used by hub, so you can safely delete them from your .gitconfig.

It seems that something is broken during authentication with your GHE instance. Maybe instead of prompting you with 2FA code, the application redirects to some HTML page and that's why we get the No decoder found error. Have you tried using HUB_VERBOSE=true hub fork to see the verbose HTTP dump and paste us that? Remember to strip away all sensitive information.

You can put your OAuth token manually by saving this as ~/.config/hub:

---
ghe.mycompany.net:
- protocol: https
  user: nik
  oauth_token: TOKEN

Can you also tell me which GHE version are you running? Open its web interface in the browser and hover your mouse over the octocat icon in the footer.

@nikreiman
Copy link
Author

nikreiman commented Oct 28, 2014

I just tried manually putting the 2FA token in ~/.config/hub, still no luck. For the record, here's what happens:

master u=!po-test> HUB_VERBOSE=true hub fork
github.com username: nik
ghe.mycompany.net password for nik (never stored): 
\e[36m> GET https://ghe.mycompany.net/api/v3/authorizations\e[m
\e[36m> Authorization: Basic [REDACTED]\e[m
\e[36m< HTTP 200\e[m
\e[36m[{"id":786,"url":"https://ghe.mycompany.net/api/v3/authorizations/786","app":{"name":"GitHub Gist","url":"https://ghe.mycompany.net/gist","client_id":"REMOVED"},"token":"TOKENREMOVED","note":null,"note_url":null,"created_at":"2014-07-10T07:58:11Z","updated_at":"2014-10-07T10:04:04Z","scopes":[]},{"id":1058,"url":"https://ghe.mycompany.net/api/v3/authorizations/1058","app":{"name":"GitHub for Windows","url":"https://windows.github.com/","client_id":"REMOVED"},"token":"TOKENREMOVED","note":"GitHub for Windows on beast-vm-win81","note_url":null,"created_at":"2014-10-14T12:41:11Z","updated_at":"2014-10-14T12:41:11Z","scopes":["user","repo","write:public_key"]},{"id":1083,"url":"https://ghe.mycompany.net/api/v3/authorizations/1083","app":{"name":"hub (API)","url":"http://hub.github.com/","client_id":"REMOVED"},"token":"TOKENREMOVED","note":"hub","note_url":"http://hub.github.com/","created_at":"2014-10-22T08:36:40Z","updated_at":"2014-10-23T14:43:17Z","scopes":["admin:org","admin:public_key","admin:repo_hook","delete_repo","gist","notifications","repo","user"]}]\e[m
\e[36m> GET https://ghe.mycompany.net/user\e[m
\e[36m> Authorization: token [REDACTED]\e[m
\e[36m< HTTP 302
< Location: https://ghe.mycompany.net/login?return_to=https%3A%2F%2Fghe.mycompany.net%2Fuser\e[m
\e[36m<html><body>You are being <a href="https://ghe.mycompany.net/login?return_to=https%3A%2F%2Fghe.mycompany.net%2Fuser">redirected</a>.</body></html>\e[m
\e[36m> GET https:///login\e[m
\e[36m< HTTP 200\e[m
\e[36m<!DOCTYPE html>
<html class="   ">...
No decoder found for format  (text/html; charset=utf-8)

@nikreiman
Copy link
Author

@mislav Sorry, forgot to include GHE. We have version 11.10.344. Some of my colleagues have supposedly gotten hub working, so I don't think it's a server thing.

@owenthereal
Copy link
Contributor

I just tried manually putting the 2FA token in ~/.config/hub, still no luck.

@nikreiman the token you'd need to put in ~/.config/hub is the oauth token, not the 2FA one:

---
ghe.mycompany.net:
- protocol: https
  user: nik
  oauth_token: TOKEN

You could follow this link to generate a oauth token. The link is for GH but it should apply to GHE.

owenthereal added a commit that referenced this issue Oct 28, 2014
From #660 (comment), the colorized verbose output is broken. The old implementation tries to use ‘\e’ which is not recognized in a Go string. Let’s Use ‘\033’ instead.
@owenthereal
Copy link
Contributor

@nikreiman I've found the broken code and fixed it in #669. The problem is when getting current user, hub 2.x uses the wrong URL GET https://ghe.mycompany.net/user. It should use GET https://ghe.mycompany.net/api/v3/user instead since the /api/v3 prefix is mandatory for GHE.

owenthereal added a commit that referenced this issue Oct 28, 2014
GHE is using /api/v3 as the path prefix for all API URLs. There’s one miss case when getting current user.

This is to fix #660 (comment)
@nikreiman
Copy link
Author

@jingweno nice, looks like we finally found the root of the problem. :) Thanks for the fix!

@owenthereal
Copy link
Contributor

@nicklewis I've merged the fixes to master. Could you try brew upgrade --HEAD hub and try hub fork again?

@nikreiman
Copy link
Author

I'm not using brew actually (I'm on Linux), so I just fetched HEAD from the repo and built it by hand. I can at least authenticate now, but it seems to die somewhere else:

master u=!po-test> HUB_VERBOSE=1 hub fork
> GET https://ghe.mycompany.net/api/v3/repos/nik/test
> Authorization: token [REDACTED]
< HTTP 404
{"message":"Not Found","documentation_url":"https://developer.github.com/v3"}
> POST https://ghe.mycompany.net/api/v3/repos/po/test/forks
> Authorization: token [REDACTED]
< HTTP 404
{"message":"Not Found","documentation_url":"https://developer.github.com/v3"}
master u=!po-test> git remote -v show
origin  [email protected]:po/test.git (fetch)
origin  [email protected]:po/test.git (push)
master u=!po-test> hub --version
git version 1.9.1
hub version 2.2.0-preview1

@nikreiman
Copy link
Author

BTW should I open a new issue for this problem?

@mislav
Copy link
Owner

mislav commented Oct 29, 2014

Does po/test repository exist on your GHE instance? It's weird that trying to create a fork off it via API would return a 404. Do you have sufficient permissions for that repo?

@nikreiman
Copy link
Author

po/test exists and is viewable and forkable by me. I forked it by hand in a web browser just now, but deleted it again to test with hub.

@mislav
Copy link
Owner

mislav commented Oct 29, 2014

The POST /api/v3/repos/po/test/forks looks good to me, so I don't know what could be wrong. I'll do some digging in Enterprise API to see why might we return a 404 here.

Ping @pengwynn for emotional support

@pengwynn
Copy link

@nikreiman a couple of questions for ya:

  • How old is your Enterprise install?
  • What scopes are on your token?
curl -I -u username:$MY_TOKEN https://ghe.mycompany.net/api/v3/user | grep "X-OAuth-Scopes"

@mislav
Copy link
Owner

mislav commented Oct 29, 2014

@pengwynn They're running very new: 11.10.344

@owenthereal
Copy link
Contributor

@nikreiman were you able to try @pengwynn's suggestions? I updated the title and description and reopening this issue.

@owenthereal owenthereal reopened this Nov 4, 2014
@owenthereal owenthereal changed the title Error while forking, "No decoder found for format" hub fork fails when GHE returns 404 Nov 4, 2014
@nikreiman
Copy link
Author

@pengwynn Sorry for the late response, regarding your second question, the scope should be everything. I have tried all sorts of combinations under the scopes page in application settings, including ticking all of the boxes, none of the boxes, default number of boxes, etc. Same result every time.

@mislav
Copy link
Owner

mislav commented Sep 27, 2015

@nikreiman Is this still an issue. Is it possible that you've upgraded your Enterprise instance since then?

@nikreiman
Copy link
Author

@mislav I'm not sure, I gave up on hub some time ago, and I also no longer work at the company with GHE.

@mislav
Copy link
Owner

mislav commented Feb 7, 2019

Closing due to stale

@mislav mislav closed this as completed Feb 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants