mark icon indicating copy to clipboard operation
mark copied to clipboard

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

Open roman6600 opened this issue 2 years ago • 14 comments

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?

roman6600 avatar Sep 08 '21 11:09 roman6600

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.

kovetskiy avatar Sep 08 '21 21:09 kovetskiy

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

langecode avatar Sep 10 '21 08:09 langecode

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

NickBelhomme avatar Sep 10 '21 09:09 NickBelhomme

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.

kovetskiy avatar Nov 02 '21 05:11 kovetskiy

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 :)

ConradMearns avatar Nov 02 '21 23:11 ConradMearns

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?

hyousif-pkglobal avatar Nov 03 '21 16:11 hyousif-pkglobal

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

On Wed, Nov 3, 2021, 22:51 hyousif-pkglobal @.***> wrote:

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?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/kovetskiy/mark/issues/113#issuecomment-959724421, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACAN7ZE2G62YXK7CTF7CU23UKFZAPANCNFSM5DURTE5A . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

kovetskiy avatar Nov 04 '21 08:11 kovetskiy

Awesome! It works now. Thanks!

hyousif-pkglobal avatar Nov 04 '21 13:11 hyousif-pkglobal

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

langecode avatar Nov 08 '21 12:11 langecode

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.

markszabo avatar Jan 06 '22 08:01 markszabo

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.

dreki avatar Jul 26 '22 15:07 dreki

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.

alexzimmer96 avatar Aug 18 '22 14:08 alexzimmer96

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.

gragib avatar Oct 19 '22 16:10 gragib

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.

joyfulrabbit avatar Dec 08 '22 21:12 joyfulrabbit