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

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

I created a basic static local site using Jekyll , which I want to click on the GitHub.com repository (I want to host the site on <username>.imtqy.com and, according to the instructions on the GitHub pages, the repo should have the same name as the folder containing the local site.

I have two-factor authentication for logging in to GitHub, so following this message , I pass the OTP / token (generated by the Application Settings in the request header using the -H "X-GitHub-OTP":<token> option -H "X-GitHub-OTP":<token> . I can log in the system (this post previously raised the question that the Github login is not working, which was caused by not closing the "X-GitHub-OTP" correctly), but now the login works, but now I get the answer with code 400. Here is the command curl I use:

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

and reply 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> 
+1
source share
1 answer

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

In addition to basic authentication credentials, you must send a user authentication code (i.e. a one-time password) to the X-GitHub-OTP header. Because these authentication codes expire quickly, we recommend that you use the authorization API to create an access token and use this token to authenticate through OAuth to access the API.

Alternatively, you can create access tokens from the "Personal Access Access Current" section of the settings page.

0
source

Source: https://habr.com/ru/post/1444655/


All Articles