Skip to content
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

Confluence API returned unexpected status: 401 - on self-hosted-confluence with an API-token #113

Open
roman6600 opened this issue Sep 8, 2021 · 14 comments

Comments

@roman6600
Copy link

Hi,

our company uses a self-hosted confluence. When I try to upload files with my username and password it works without any issues. But when I try to use my created token I get a 401-error. I created the token with the following method: https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html#UsingPersonalAccessTokens-CreatingPATsinapplication

I tried to use following command:
mark -u <my_username> -p <my_token> -b 'https://my-company-wiki.net/' -f confluence_test.md
and
mark -p <my_token> -b 'https://my-company-wiki.net/' -f confluence_test.md
but both commands return the same output:

2021-09-08 13:32:08.174 FATAL unable to resolve page
                              └─ error while finding page "test"
                                 ├─ Confluence API returned unexpected status: 401 (Unauthorized)
                                 └─ title: test

When I use the token to create a new page directly via curl it also works:

curl -X POST -H "Authorization: Bearer <my_token>" -H 'Content-Type: application/json' -d '{"type":"page","title":"test", space":{"key":"~my_username"}, "body":{"storage":{"value":"<p>This is a new page</p>","representation":"storage"}}}' "https://my-company-wiki.net/rest/api/content/"

Is it even possible to use a token with mark or have I made a mistake?

@kovetskiy
Copy link
Owner

Hi, it didn't require an Authorization header before and we could pass a token as a password. Sounds like it's not possible now.

@langecode
Copy link

I am seeing the same issue. The Confluence documentation does say that Personal Access Tokens is supposed to be put in a Bearer authorization header: https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html

@NickBelhomme
Copy link

NickBelhomme commented Sep 10, 2021

Same issue here.

2021-09-10 09:22:31.497 FATAL unable to resolve page
                              └─ error while finding page "Action Resource"
                                 ├─ Confluence API returned unexpected status: 401 (Unauthorized)
                                 └─ title: Action Resource
bash-5.0# mark --version
6.2

@kovetskiy
Copy link
Owner

Is it a hosted version of Confluence you are using? If so, which version?

I have no problems accessing the cloud version of Confluence while using a token as a password.

@ConradMearns
Copy link

ConradMearns commented Nov 2, 2021

I think I may be having the same issue. We're on 7.4.11...

Using a config file with username and password. Through --trace on /confluence/rest/api/content/?expand=ancestors%2Cversion&spaceKey=~mear593&title=Testin&type=page

I get

Basic Authentication Failure - Reason : AUTHENTICATED_FAILED Description The request has not been applied because it lacks valid authentication credentials for the target resource.

If I access the same URL through the browser, all works fine

EDIT:

Actually just figured it out... I was using my company email address as a username, however the X-AUSERNAME header in my browser was my network username.

I switched my mark username to be the same as my network username and everything works :)

@hyousif-pkglobal
Copy link

Hello,

I used username and API token to access the confluence page and I am not getting the 401 error message. However, I am getting 404 even though the page exists:

Run for file in $(find -type f -name '*.md'); do echo "> Sync $file"; mark -u *** -p *** -b https://myspace.atlassian.net/ -f $file || exit 1;echo; done

Sync ./README.md
2021-11-03 16:40:32.781 INFO processing ./README.md
2021-11-03 16:40:33.137 FATAL unable to resolve page
└─ can't obtain home page from space "myspace"
├─ Confluence API returned unexpected status: 404 (Not Found)
└─ title: README_MD_FILE
Error: Process completed with exit code 1.

Any thought?

@kovetskiy
Copy link
Owner

kovetskiy commented Nov 4, 2021 via email

@hyousif-pkglobal
Copy link

Awesome! It works now.
Thanks!

@langecode
Copy link

For on-prem Confluence it seems the is both "personal access token" and "api tokens". The latter actually works using the basic authentication header. It is possible to issue API token (instead of PAT tokens) by visiting the Confluence URL <confluence-base-path>/plugins/servlet/de.resolution.apitokenauth/admin

@markszabo
Copy link

I'm also using it with an on-prem Confluence and running into the same issue (can't use PAT, only password). Would you accept a PR adding support for PAT?

I'd be happy to extend gopencils to support bearer tokens, and then use it here to support PAT.

@dreki
Copy link

dreki commented Jul 26, 2022

Hi, in case of cloud you should add /wiki to the URL as far as I remember.

This was helpful to me. I recommend including it in the documentation for mark.

@alexzimmer96
Copy link

I've just learned that if you leave the username empty and specify your PAT as password, it will be sent as bearer token. This way i got the authentication working.

@gragib
Copy link

gragib commented Oct 19, 2022

I've just learned that if you leave the username empty and specify your PAT as password, it will be sent as bearer token. This way i got the authentication working.

This is the way.

@joyfulrabbit
Copy link
Contributor

I am using a hosted confluence (7.13.7). I can confirm commenting out the "username = " is the -only- way a personal access token works for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests