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>
0

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

9 Comments

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" }
@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?
Hi, sure, that's fine. This question seems identical. I'll have a look later.
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.
@ramius, I just saw this comment. But you have accepted the answer... Is everything working now?
|
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"}'

1 Comment

Welcome to SO. Please do format your answers in future.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.