Skip to content

API Authorization: header not working #4243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
stevegt opened this issue Jun 13, 2018 · 2 comments
Closed

API Authorization: header not working #4243

stevegt opened this issue Jun 13, 2018 · 2 comments

Comments

@stevegt
Copy link
Contributor

stevegt commented Jun 13, 2018

The Authorization: header doesn't seem to be working as of 2e05ffd. I haven't yet figured out what's causing this behavior, or if it's something I'm doing wrong. Seeing some possible similarities with some of the symptoms of #3842, particularly the 401 response described there when using Authorization:.

How to duplicate:

  • Using the /api/swagger web UI, hit the 'Authorize' button and put your token into the AuthorizationHeaderToken value field. Ensure you are logged out of all other authorization methods. Ensure you are logged out of the gitea web UI (no cookies stored in your browser).
  • Create a new issue using the swagger web UI; this will fail with a 401 Unauthorized error.
  • Now copy and execute the curl command given by the swagger web UI. It also fails. Adding a -i flag to curl shows that it is returning a 401 Unauthorized:
curl -X POST "http://localhost:4000/api/v1/repos/test1/test1/issues" -H "accept: application/json" -H "Authorization: 65eaa9c8ef52460d22a93307fe0aee76289dc675" -H "Content-Type: application/json" -d "{ \"body\": \"testing\", \"title\": \"test 17\"}" -i
HTTP/1.1 401 Unauthorized
Set-Cookie: lang=en-US; Path=/; Max-Age=2147483647
Set-Cookie: i_like_gitea=7e17b9f254cd0cc4; Path=/; HttpOnly
Set-Cookie: _csrf=vW3ET5wQ62_IHnj5j08A9KUfXQM6MTUyODkwODc5OTkyOTI5OTUxNw%3D%3D; Path=/; Expires=Thu, 14 Jun 2018 16:53:19 GMT
X-Frame-Options: SAMEORIGIN
Date: Wed, 13 Jun 2018 16:53:19 GMT
Content-Length: 0
  • Go back and hit the Authorize button again, log out of AuthorizationHeaderToken, and instead paste your token in the Token value field.
  • Try creating a new issue using the swagger web UI again; this will succeed.
@stevegt stevegt changed the title Authorization: header not working consistently API Authorization: header not working consistently Jun 14, 2018
@stevegt stevegt changed the title API Authorization: header not working consistently API Authorization: header not working Jun 14, 2018
@stevegt
Copy link
Contributor Author

stevegt commented Jun 14, 2018

Closing for now because I'm probably an idiot -- the Authorization: header probably isn't supposed to work with the same token type that works in the query string, and I should probably know better.

@stevegt stevegt closed this as completed Jun 14, 2018
@stevegt
Copy link
Contributor Author

stevegt commented Jun 14, 2018

Okay, for anyone landing here from google -- the way to get the Authorization: header to work from gitea API clients is to use your normal API key token, the same one you would use in the token= string in a GET request, but with the word token prepended. Like this:

Authorization: token 65eaa9c8ef52460d22a93307fe0aee76289dc675

In a curl command, for instance, this would look like:

curl -X POST "http://localhost:4000/api/v1/repos/test1/test1/issues" -H "accept: application/json" -H "Authorization: token 65eaa9c8ef52460d22a93307fe0aee76289dc675" -H "Content-Type: application/json" -d "{ \"body\": \"testing\", \"title\": \"test 20\"}" -i

The code that parses this is at

if len(auths) == 2 && auths[0] == "token" {

Some related points:

stevegt added a commit to stevegt/gitea that referenced this issue Jun 24, 2018
* Build on work by @tungsheng

* Address issues raised in go-gitea#4037, go-gitea#3673, and go-gitea#4243

* Close go-gitea#4247

Signed-off-by: Steve Traugott <[email protected]>
lunny pushed a commit that referenced this issue Jun 25, 2018
* add api user guides in doc

* update user-guides api page

* fix typo: user guides -> user guide

* move api-usage page under advanced category

* flesh out API usage docs

* Build on work by @tungsheng

* Address issues raised in #4037, #3673, and #4243

* Close #4247

Signed-off-by: Steve Traugott <[email protected]>
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant