GitHub guide explains 2 way to authorize but looks neither of those works with the Release files.
as a result of:
curl -u 'username' -L -o a.tgz https://github.com/company/repository/releases/download/TAG-NAME/A.tgz
there always is something like
<!DOCTYPE html>
<!--
Hello future GitHubber! ...
To download release file from private repo, you can use Personal access token which can be generated at settings/tokens with Full control of private repositories scope.
Then download the asset with
curl
command (change with appropriate values):where:
:owner
is your user or organisation username;:repo
is your repository name;:id
is your asset id, can be found in tag release URL, like::token
is your personal access token (can be created at/settings/tokens
;See: Repositories API v3 at GitHub
Here is the Bash script which can download asset file given specific name of file:
Before running, you need to set your
GITHUB_API_TOKEN
with your GitHub token (see:/settings/tokens
at GH). This can be placed in your~/.secrets
file, like:Example script usage:
where name is your filename (or partial of it). Prefix script with
TRACE=1
to debug it.In case you wonder why
curl
fails sometimes with (as mentioned in other answer):when running like:
this is because you're specifying multiple mechanism at the same time, so S3 server doesn't know which one to use, therefore you have to choose only one, such as:
X-Amz-Algorithm
query parameterX-Amz-Signature
)Authorization: token <token>
)and since GitHub redirects you from asset page (when requesting
application/octet-stream
), it populates credentials automatically in query string and sincecurl
is passing over the same credentials in the request header (which you've specified), therefore they're conflicting. So as for workaround you can useaccess_token
instead.An easier working solution is to use .netrc to store credentials. This way, curl does not forward credentials to Amazon S3 Bucket
In
~/.netrc
file (should be created with 0600 file permission):Then use the curl -n option to use .netrc:
Here is
curl
&jq
one;)liner:Change parts surrounded with
<>
with your data. To generateauth_token
go to github.com/settings/tokensIf you like to login with password use this (note it will ask for password twice):
I found out the answer in this comment: https://github.com/request/request/pull/1058#issuecomment-55285276
curl
is forwarding the authentication header in the request to the AmazonS3 bucket, where the Github release assets are stored. Error response from S3:One line wget solution:
Try:
curl -i -H "Authorization: token <token>" -H "Accept:application/octet-stream" https://<token>:@api.github.com/repos/:owner/:repo/releases/assets/:id
, for some more details. Add-L
to see the S3 error message.Here is a "one-liner" using
wget
for making HTTP requests andpython
for JSON parsing:To use it, just replace
<oauth-token>
,<owner>
,<repo>
,<tag>
and<download-name>
with appropriate values.Explanation:
export AUTH_TOKEN=<oauth-token>
) sets GitHub OAuth token which is used by the subsequentwget
commands.wget -O - https://api.github.com/repos/<owner>/<repo>/releases/tags/<tag>?access_token=$AUTH_TOKEN
part gets GitHub release information from a tag name and prints it on stdout.python -c 'import sys, json; print json.load(sys.stdin)["assets"][0]["id"]'
part parses JSON from stdin and extracts theid
of the (first) release asset.wget --header='Accept:application/octet-stream' -O <tarball-name>.tar.gz https://api.github.com/repos/<owner>/<repo>/releases/assets/$ASSET_ID?access_token=$AUTH_TOKEN)
) gets a single GitHub release asset by id and stores it to a file.Seems both authentication methods only work for the API endpoints. There's an API endpoint for downloading release assets (docu):
But one will need to know the asset's numerical ID for that. I asked their support whether they could add an API endpoint to download release assets by name (like they have for tarballs).
Update: Response from Github support: