Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse: can't push to Github, authorization failed

Tags:

eclipse

egit

Eclipse/EGit/Github were all working fine yesterday. I received a "you have updates" message from Eclipse this morning and did a general software update of everything.

When I tried to pull changes from my private project on Github (Team -> Pull), I got an authorization error. Fine, per this answer I deleted my security credentials in Window -> Preferences -> General -> Security -> Secure Storage -> Contents -> Delete. Tried to pull, entered my credentials at the prompt, and it worked fine.

But when I try to push (Team / Push to upstream) I get "Failed pushing to myproject - origin, https://github.com/username/myproject.git: 401 Authorization Required"

If I go to the command line and type "git push origin master" it works fine.

So it looks like something bad happened to Eclipse. Anyone know how to get around this authorization error from within Eclipse?

(I'm not using two-factor authentication on Github. I'm using Windows 10 with Eclipse Neon fully patched and up to date, so far as I know.)

like image 292
ccleve Avatar asked Dec 25 '22 01:12

ccleve


2 Answers

I had the same problem. Workaround from this post was useful: https://www.eclipse.org/forums/index.php/t/1081631/

Help -> Install New Software

Work with: http://download.eclipse.org/mpc/releases/1.5.1a

Select the "EPP Marketplace Client"

Proceed with defaults

like image 188
cache Avatar answered Jan 09 '23 21:01

cache


I too had the same problem. Problem is with Latest Neon Eclipse in java.net.Authenticator module.

According to Christian Halstrick:

The problem is that during a push two requests are sent to the server, first a GET and then a POST (containing the pack data). The first GET request sent anonymously is rejected with 401 (unauthorized). When an Authenticator is installed the java.net classes will use the Authenticator to ask the user for credentials and retry the request. But this happens under the hood and JGit level code doesn't see that this happens.

The next request is the POST but since JGit thinks the first GET request went through anonymously it doesn't add authentication headers to the POST request. This POST of course also fails with 401 but since this request contains a lot of body-data streamed from JGit (the pack file!) the java.net classes can't simply retry the request with authorization headers. The whole process fails.

If no Authenticator is installed then the situation is better. First anonymous GET request fails with 401 and this bubbles up to JGit. Then JGit asks the user for credentials (with the help of the installed CredentialsProviders) and retries with basic authentication headers. This succeeds and when the POST request is sent JGit knows about the succesfull authorization and adds the correct header directly to the POST. The request succeeds.

Note that EGit uses JGit as Git implementation.

The solution is to change the version of Eclipse.

I used Spring tool Suite and it worked fine for me. Spring tool Suite is customized all-in-one Eclipse based distribution ide.

like image 39
Amit Saroj Avatar answered Jan 09 '23 23:01

Amit Saroj