Users/:username/tokens


#1

Hi, there seems to be an issue with the authorisation of access tokens using the API. Regardless of username/password combination, basic authorisation headers, or URL based tokens all from admins and not, the post and get commands return a 401.

Am i missing something? and has anyone had this working?


#2

If none is working, then either you put wrong credentials, or you’re connecting to the wrong Gogs instance. Or… if you don’t delete post template so quickly… I can offer more help.


#3

Hi Unknwon, thanks for getting back. What do you mean by don’t delete post template? I can 100% confirm that i’m using the right gogs instance (only have 1 running) and i have confirmed the username/password details over and over. All other API calls are working fine.


#4

The template is the default text in your box before you type anything for a new post.


#5

sorry, i must be missing something. I’m calling this both with a browsers and postman so there is no default text. but i guess you mean the post JSON e.g.
{
“name”: “gogs”
}

i’m just call the URL direct like: https://myurl/api/v1/users/mynewuser/tokens?token=36336c37666cd5dc35f822ce54a0a6b1e1e1b710


#6


#7

ah sorry, my bad

Can reproduce on try.gogs.io @

https://try.gogs.io/api/v1/users/ahendry/tokens?token=4499221b5af78f2eeb7172208a2b500329630c8f

application token is create under user settings: name = test (is currently denoted as active, used in last 7 days)

my info:
Gogs Version: 0.11.29.0727
Mysql data store
runing gogs/gogs docker instance


#8

You can not get/create access token with access tokens, this is prohibited by design. You must use basic authentication for this particular API end point.


#9

Hi, so i’ve got it working. If you use a direct cURL command or call it through code it works e.g.

CURL -

curl -X GET
https://try.gogs.io/api/v1/users/ahendry/tokens
-H ‘authorization: Basic YWhlbmRyeToxMjM0NTY3’
-H ‘cache-control: no-cache’
-H ‘content-type: application/json’
-H ‘postman-token: 0b37aa53-c01e-ea27-a1a4-26a1f17a98bf’

Using postman or browser fails (browser i can understand but not sure what is going on with postman as it works for everything else)

Cheers for the support