API ignores basic auth (for creating API key) #11102

Closed
opened 2025-11-02 09:27:39 -06:00 by GiteaMirror · 3 comments
Owner

Originally created by @lonix1 on GitHub (Jun 25, 2023).

Description

I am using ansible to provision a gitea server and configure it. I created an admin account using the CLI.

There are some things that can only be done with the API, but to use it one needs an API key. And I can't do that manually - I want to automate that.

So using basic auth, I tried:

curl -X POST \
  'http://localhost:3000/api/v1/users/username/tokens' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -u username:password \
  -d '{ "name": "hello" }'

Error:

Only signed in user is allowed to call APIs.

So I tried in the swagger interface. In the auth popup I entered username/password for the basic auth option, then I tried the endpoint. Result:

Only signed in user is allowed to call APIs.

I double checked my syntax with the docs here, and it seems correct. And my username/password is correct as I use it in the gitea frontend.

Gitea Version

1.20.0-rc2

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

linux

How are you running Gitea?

docker rootful

Database

SQLite

Originally created by @lonix1 on GitHub (Jun 25, 2023). ### Description I am using ansible to provision a gitea server and configure it. I created an admin account using the CLI. There are some things that can only be done with the API, but to use it one needs an API key. And I can't do that manually - I want to automate that. So using basic auth, I tried: ``` curl -X POST \ 'http://localhost:3000/api/v1/users/username/tokens' \ -H 'accept: application/json' \ -H 'Content-Type: application/json' \ -u username:password \ -d '{ "name": "hello" }' ``` Error: > Only signed in user is allowed to call APIs. So I tried in the swagger interface. In the auth popup I entered username/password for the basic auth option, then I tried the endpoint. Result: > Only signed in user is allowed to call APIs. I double checked my syntax with the [docs here](https://docs.gitea.com/next/development/api-usage#generating-and-listing-api-tokens), and it seems correct. And my username/password is correct as I use it in the gitea frontend. ### Gitea Version 1.20.0-rc2 ### Can you reproduce the bug on the Gitea demo site? No ### Log Gist _No response_ ### Screenshots _No response_ ### Git Version _No response_ ### Operating System linux ### How are you running Gitea? docker rootful ### Database SQLite
GiteaMirror added the type/bug label 2025-11-02 09:27:39 -06:00
Author
Owner

@lonix1 commented on GitHub (Jun 25, 2023):

This is not documented, but is possible via the CLI:

$ gitea admin user generate-access-token --username username --token-name hello

Thanks to @delvh for letting me know in the discord chat!

@lonix1 commented on GitHub (Jun 25, 2023): This is [not documented](https://docs.gitea.com/1.20/administration/command-line#generate), but is possible via the CLI: ``` $ gitea admin user generate-access-token --username username --token-name hello ``` Thanks to @delvh for letting me know in the discord chat!
Author
Owner

@delvh commented on GitHub (Jun 25, 2023):

By the way, docs PR are always welcome, if you want to improve the documentation.

@delvh commented on GitHub (Jun 25, 2023): By the way, docs PR are always welcome, if you want to improve the documentation.
Author
Owner

@lonix1 commented on GitHub (Jun 25, 2023):

LOL - I just submitted a PR, this second! https://github.com/go-gitea/gitea/pull/25504

@lonix1 commented on GitHub (Jun 25, 2023): LOL - I just submitted a PR, this second! https://github.com/go-gitea/gitea/pull/25504
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#11102