HTTPS basic auth is a quick and easy solution, but it's not always the most secure. For those cases you can use OAuth instead.
Create a token
To create a token, you must POST to https://api.github.com/authorizations with note
and scopes
values in the data hash.
$ curl -u 'username' -d '{"scopes":["repo"],"note":"Help example"}' \ https://api.github.com/authorizations# Enter host password for user 'username': [type password]# {# "scopes": [# "repo"# ],# "token": "your_token",# "app": {# "url": "http://developer.github.com/v3/oauth/#oauth-authorizations-api",# "name": "Help example (API)"# },# "url": "https://api.github.com/authorizations/123456",# "note": "Help example",# "note_url": null,# "id": 123456,# }
In case you need to revoke this token for any reason, the new authorization will show up in your OAuth settings with the note you used. The scopes
list determines what level of access the token provides. Check the scopes overview in the API docs for a complete list.
Using the token
To use the token, pass it in a header named "Authorization"
$ curl -H "Authorization: token your_token" \ https://api.github.com/repos/user/repo