Download ZIP file of private gitea repository

I can use the chrome browser to download the ZIP file of a private gitea repository https://someurl.com/mydir/archive/master.zip after entering username and password.

I try to use curl to download the same ZIP file.

I followed gitea API:

and tried:

curl -XPOST -H "Content-Type: application/json"  -k -d '{"name":"test"}' -u username:password https://gitea.your.host/api/v1/users/<username>/tokens
curl --request GET --url https://yourusername:password@gitea.your.host/api/v1/users/<username>/tokens

Both curls were successful.

Then I tried:

curl --location-trusted --user myusername:mypassword --request GET -H "Authorization: token 16c3e37d" -O --url https://someurl.com/mydir/archive/master.zip

I got this file, its size is much smaller than the expected file size.
Its content, edited for brevity, is:

<form class="ui form" action="/user/login" method="post">
<input type="hidden" name="_csrf" value="MPetQDF">
<div class="required inline field">
  <label for="user_name">Username or Email Address</label>
  <input id="user_name" type="text" name="user_name" value="" autofocus required>
</div>

<div class="required inline field">
  <label for="password">Password</label>
  <input id="password" name="password" type="password" value="" autocomplete="current-password" required>
</div>


</form>

<a href="/api/swagger">API</a>

<script src="/assets/js/index.js?v=a30bc3"></script>


How to proceed further?

Please help.
Thanks.

The reason it dosn’t work is simply because gitea’s frontend and it’s API are seperated.
Meaning, when you authenticate via the API you are only allowed to use the API.

What you need is the /api/v1/repos/<owner>/<repo>/archive/<archive> endpoint.
So the correct curl would be:

curl -H "Authorization: token xxxx" -O https://your.gitea.host/api/v1/repos/<owner>/<repo>/archive/master.zip

(Note that the token needs to be the complete one, not the truncated one found in token_last_eight)

You can also see (and even test!) the API right from gitea’s frontend via the builtin swagger documentation, located at https://your.gitea.host/api/swagger.

1 Like