3

I'm having problems using curl to create a repo on my GitHub.com account (no ssh).

I have created a basic static local site using Jekyll which I want to push to the GitHub.com repo (I want to host the site on <username>.github.io and according to the instructions on GitHub pages the repo must have the same name as the folder containing the local site.

I have two-factor authentication enabled for the GitHub login, so following this post I am passing an OTP/token (generated on Applications settings in the request header using the option -H "X-GitHub-OTP":<token>. I can log in (this post previously raised an issue about the Github login not working, which was due to not closing the string "X-GitHub-OTP" properly), but now the login works but I now receive a response with a 400 code. Here is the curl command I am used:

$username="<username>"
$reponame="$username.github.io"
$token="<token>"
$apidom="https://api.github.com/user/repos/"
$curl -u $username -H '{"X-GitHub-OTPOTP":$token}' -d '{"name":$reponame,"description":$repodesc}' $apidom

and the response message:

<p><strong>We didn't receive a proper request from your browser.</strong></p>
<p>Sorry about that. Please try refreshing and contact us if the problem persists.</p>
<div id="suggestions">
<a href="https://github.com/contact">Contact Support</a> &mdash;
<a href="https://status.github.com">GitHub Status</a> &mdash;
<a href="https://twitter.com/githubstatus">@githubstatus</a>
</div>
Community
  • 1
  • 1

2 Answers2

1

Since you have two-factor authentication enabled, you will need to send a special HTTP header:

In addition to the Basic Authentication credentials, you must send the user’s authentication code (i.e., one-time password) in the X-GitHub-OTP header. Because these authentication codes expire quickly, we recommend using the Authorizations API to create an access token and using that token to authenticate via OAuth for most API access.

Alternately, you can create access tokens from the Personal Access Token section of your application settings page.

Community
  • 1
  • 1
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • Thanks, I created personal token using Settings but it's still not working, using the same curl command format (with correct password and token) I'm now getting this message: `{ "message": "Must specify two-factor authentication OTP code.", "documentation_url": "https://developer.github.com/v3/auth#working-with-two-factor-authentication" }` –  Jan 02 '15 at 20:01
  • @ramius, the URL in that error message is the same one I linked to in my answer. Can you edit your question to clarify exactly what you have done to generate this message? – ChrisGPT was on strike Jan 02 '15 at 20:22
  • Hi, sure, that's fine. [This question](http://stackoverflow.com/q/20443135/997225) seems identical. I'll have a look later. –  Jan 02 '15 at 20:30
  • thanks but I'm having another problem with the HTTP response from the `curl` statement, as described in my updated question. ANy help would be appreciated. –  Jan 03 '15 at 13:45
  • @ramius, I just saw this comment. But you have accepted the answer... Is everything working now? – ChrisGPT was on strike Jan 03 '15 at 15:47
  • Well, yes and no - manually creating the remote repo this way does still not work (I created the repo directly on GitHub.com), but I accepted the answer because it indicates what the problem may be - sending the OTP code in the header using `-H '{"X-GitHub-OTPOTP":$token}` with `curl`. The HTTP response, which I have stored, indicates that the browser does not form the request correctly, but as you can see from the session output above I am doing exactly what you have suggested, ref. also [here](http://stackoverflow.com/a/20598750/997225). –  Jan 03 '15 at 16:11
  • Could it be browser specific (I use Firefox v. 34.0 and some plugins like HTTPS Everywhere)? –  Jan 03 '15 at 16:13
  • @ramius, why would your web browser have anything to do with this? Aren't you running `curl` on the command-line? – ChrisGPT was on strike Jan 04 '15 at 03:23
  • CL of course, I don't know why I mentioned the browser, must have been thinking about another post. I've solved the problem - kind of - by creating the repo directory on GitHub.com and was able to do a `git push` from local. There's also appears to be good solution [here](http://stackoverflow.com/a/24282548/997225). –  Jan 04 '15 at 11:07
1

Two factor authentication

curl -u "YOUR_USERNAME_HERE" \
    -H "X-Github-OTP:YOUR_OTP_CODE_HERE" \
    https://api.github.com/user/repos
    -d '{"name": "test"}'

Normal authentication

curl -u "YOUR_USERNAME_HERE" \
    -H https://api.github.com/user/repos \
    -d '{"name":"Your repo name here"}'
Petr Hejda
  • 40,554
  • 8
  • 72
  • 100
Andraide
  • 11
  • 1