Description
In trying to write a Drone Secrets Extension to allow Drone pipelines to obtain a per-pipeline Gitea API Token automatically I ran into 2 problems:
- Trying to create a token for a user does not work when using a token for authorization:
curl -X 'POST' \
'https://gitea.test/api/v1/users/test123/tokens' \
-H 'accept: application/json' \
-H 'Authorization: token xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
-H 'Content-Type: application/json' \
-d '{
"name": "drone_123123_2022-09-16-14-00"
}'
Response: {"message":"auth required","url":"https://gitea.test/api/swagger"}
Note: The token was created for an admin user account.
Edit: Forgot to mention the same problem seems to be present for listing and deleting tokens as well.
Trying to create API tokens for different users via the API is not possible. In the following example I'm trying to create a token for the user "test123" (the user has been created already). However the token is created for my primary user (the one specified via basic auth credentials). This requires the sudo get param, the URL is however confusing because it also contains a username path param.
curl -X 'POST' \
'https://gitea.test/api/v1/users/test123/tokens' \
-H 'accept: application/json' \
-u "admin:xxxxxxxx" \
-H 'Content-Type: application/json' \
-d '{
"name": "drone_123123_2022-09-16-14-00"
}'
The reason appears to be that the controller uses the request context user instead of the one specified in the path parameter:
Gitea Version
1.17.2
Can you reproduce the bug on the Gitea demo site?
Yes
Log Gist
No response
Screenshots
No response
Git Version
No response
Operating System
No response
How are you running Gitea?
- official docker image
- deployed via helm chart
Database
PostgreSQL
Description
In trying to write a Drone Secrets Extension to allow Drone pipelines to obtain a per-pipeline Gitea API Token automatically I ran into 2 problems:
Response:
{"message":"auth required","url":"https://gitea.test/api/swagger"}Note: The token was created for an admin user account.
Edit: Forgot to mention the same problem seems to be present for listing and deleting tokens as well.
Trying to create API tokens for different users via the API is not possible. In the following example I'm trying to create a token for the user "test123" (the user has been created already). However the token is created for my primary user (the one specified via basic auth credentials).This requires thesudoget param, the URL is however confusing because it also contains ausernamepath param.The reason appears to be that the controller uses the request context user instead of the one specified in the path parameter:
gitea/routers/api/v1/user/app.go
Line 101 in 548387b
Gitea Version
1.17.2
Can you reproduce the bug on the Gitea demo site?
Yes
Log Gist
No response
Screenshots
No response
Git Version
No response
Operating System
No response
How are you running Gitea?
Database
PostgreSQL