Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to authenticate to confluence server via curl

twentyonetwice May 12, 2023

I want to authenticate to our confluence server via curl.

I use 

curl https://<MY HOST>/rest/pat/latest/tokens -H "Authorization: Bearer <MY PAT>"-H "Content-Type: application/json"

which results in

<?xml version="1.0" encoding="UTF-8" standalone="yes"?><status><status-code>401</status-code><message>Client must be authenticated to access this resource.</message></status> 

 I also tried

curl https://<MY HOST>/rest/pat/latest/tokens -H "Authorization: Basic username:password"-H "Content-Type: application/json"

All results in the above response. When I call the /rest/pat/latest/tokens via browser after successful login I receive the correct tokens.

Are there any additional configuration settings in confluence to make the curl requests work?

Thanks in advance! 

1 answer

1 vote
Andrii Maliuta
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 12, 2023

Hello @twentyonetwice .

Can you try to set the url as the last parameter?

 

curl -H "Authorization: Basic ${BASE64_TOKEN}" -H "Content-Type: application/json" https://<MY HOST>/rest/pat/latest/tokens 

BASE64_TOKEN is a "user:password" string encoded to base64 format.

e.g. with user admin and admin 

echo admin:admin | base64 -> dXNlcjp1c2VyCg==

curl -H "Authorization: Basic dXNlcjp1c2VyCg==" -H "Content-Type: application/json" https://<MY HOST>/rest/pat/latest/tokens



twentyonetwice May 12, 2023

Hi Andrii, 

I already tried it the way you described. Url at last, basic authorization with base64-encoded username/password string. All tries resulted in the same response.

The docs are explaining both ways, but none of them is working.

Andrii Maliuta
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 13, 2023

@twentyonetwice ,

Just to clarify: if you use already created PAT then you should use the Bearer type:

"Authorization: Bearer $Atlas_Token"

Basic auth is used with user and password.

Also, you can try other common REST API endpoint like

https://<MY HOST>/rest/api/content/

to check access to content.

https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html  

twentyonetwice May 14, 2023

Hi @Andrii Maliuta

I've tried it both ways, the Bearer Authentication and the Basic Authentication. 

I've also tried it with rest/api/content, /rest/api/space and /rest/api/space/<SPACE_KEY>

None of those tries worked for me.

Andrii Maliuta
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 18, 2023

@twentyonetwice ,

I suppose this is some inconsistency of using the correct user with the correct permissions and corresponding token, as it works well in such cases with correct config. Could you please make sure the user has correct Global permissions and instance level permissions?

Just to make sure the access is OK, you can try to use other tool like Postman, HttPie, etc. to see if it works well.

twentyonetwice May 18, 2023

@Andrii Maliuta Finally we solve this problem. All my requests were correct, but there was a http-proxy before our confluence installation. 

Thanks for your efforts!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events