You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

api-usage.en-us.md 2.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. ---
  2. date: "2018-06-24:00:00+02:00"
  3. title: "API Usage"
  4. slug: "api-usage"
  5. weight: 40
  6. toc: true
  7. draft: false
  8. menu:
  9. sidebar:
  10. parent: "advanced"
  11. name: "API Usage"
  12. weight: 40
  13. identifier: "api-usage"
  14. ---
  15. # Gitea API Usage
  16. ## Enabling/configuring API access
  17. By default, `ENABLE_SWAGGER_ENDPOINT` is true, and
  18. `MAX_RESPONSE_ITEMS` is set to 50. See [Config Cheat
  19. Sheet](https://docs.gitea.io/en-us/config-cheat-sheet/) for more
  20. information.
  21. ## Authentication via the API
  22. Gitea supports these methods of API authentication:
  23. - HTTP basic authentication
  24. - `token=...` parameter in URL query string
  25. - `access_token=...` parameter in URL query string
  26. - `Authorization: token ...` header in HTTP headers
  27. All of these methods accept the same apiKey token type. You can
  28. better understand this by looking at the code -- as of this writing,
  29. Gitea parses queries and headers to find the token in
  30. [modules/auth/auth.go](https://github.com/go-gitea/gitea/blob/6efdcaed86565c91a3dc77631372a9cc45a58e89/modules/auth/auth.go#L47).
  31. You can create an apiKey token via your gitea install's web interface:
  32. `Settings | Applications | Generate New Token`.
  33. ### More on the `Authorization:` header
  34. For historical reasons, Gitea needs the word `token` included before
  35. the apiKey token in an authorization header, like this:
  36. ```
  37. Authorization: token 65eaa9c8ef52460d22a93307fe0aee76289dc675
  38. ```
  39. In a `curl` command, for instance, this would look like:
  40. ```
  41. curl -X POST "http://localhost:4000/api/v1/repos/test1/test1/issues" \
  42. -H "accept: application/json" \
  43. -H "Authorization: token 65eaa9c8ef52460d22a93307fe0aee76289dc675" \
  44. -H "Content-Type: application/json" -d "{ \"body\": \"testing\", \"title\": \"test 20\"}" -i
  45. ```
  46. As mentioned above, the token used is the same one you would use in
  47. the `token=` string in a GET request.
  48. ## Listing your issued tokens via the API
  49. As mentioned in
  50. [#3842](https://github.com/go-gitea/gitea/issues/3842#issuecomment-397743346),
  51. `/users/:name/tokens` is special and requires you to authenticate
  52. using BasicAuth, as follows:
  53. ### Using basic authentication:
  54. ```
  55. $ curl --request GET --url https://yourusername:yourpassword@gitea.your.host/api/v1/users/yourusername/tokens
  56. [{"name":"test","sha1":"..."},{"name":"dev","sha1":"..."}]
  57. ```