使用 `curl` 在 GitHub.com 上使用 two-factor 身份验证创建存储库

Using `curl` to create a repo on GitHub.com with two-factor authentication

我在使用 curl 在我的 GitHub.com 帐户(无 ssh)上创建存储库时遇到问题。

我使用 Jekyll 创建了一个基本的静态本地站点,我想将其推送到 GitHub.com 存储库(我想根据说明在 <username>.github.io 上托管该站点在 GitHub 页面上,repo 必须与包含本地站点的文件夹同名。

我为 GitHub 登录启用了 two-factor 身份验证,因此在请求 header 之后的 this post I am passing an OTP/token (generated on Applications settings 使用选项 -H "X-GitHub-OTP":<token>。我可以登录(这个 post 之前提出了一个关于 Github 登录不工作的问题,这是由于没有正确关闭字符串 "X-GitHub-OTP" 造成的),但现在登录工作了,但我现在收到带有 400 代码的响应。这是我使用的 curl 命令:

$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

和响应消息:

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

由于您启用了双因素身份验证,因此您需要 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.

双重身份验证

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

普通认证

curl -u "YOUR_USERNAME_HERE" \
    -H https://api.github.com/user/repos \
    -d '{"name":"Your repo name here"}'