I’m trying to use the Basic Auth REST API for Confluence cloud documented here:
https://developer.atlassian.com/cloud/confluence/rest/
Also my username in Confluence is “Admin”, will this cause problems?
However, I’m unable to authenticate as myself when I issue this request:
curl -X GET \
--user '<my-email-address>:<my-api-token>' \
-H 'Cache-Control: no-cache' \
-H 'Accept: application/json' \
-H "Content-Type: application/json" \
"https://<my-domain>.atlassian.net/wiki/rest/api/user/current"
This is the response I get (verbose from curl):
> GET /wiki/rest/api/user/current HTTP/2
> Host: <domain>.atlassian.net
> Authorization: Basic <base64 string>
> User-Agent: curl/7.54.0
> Cache-Control: no-cache
> Accept: application/json
> Content-Type: application/json
>
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 401
< server: Atlassian Proxy/0.1.205
< vary: Accept
< www-authenticate: OAuth realm="https%3A%2F%2F<domain>.atlassian.net%2Fwiki"
< cache-control: no-cache, must-revalidate
< content-type: application/json
< strict-transport-security: max-age=315360000; includeSubDomains; preload
< date: Thu, 22 Mar 2018 22:40:54 GMT
< expires: Thu, 01 Jan 1970 00:00:00 GMT
< x-xss-protection: 1; mode=block
< x-content-type-options: nosniff
<
* Connection #0 to host <domain>.atlassian.net left intact
{"message":"Request rejected because issuer is either not authorized or not authorized to impersonate","status-code":401}
My Atlassian ID is linked to my Google account and has two factor auth turned on. I’m not sure if that matters here.
Interestingly enough, this curl request works (note that it’s using the Authentication header, not Authorization). However, it Authenticates me as an anonymous user which is not what I would expect given that I’ve sent in my username and API token in the base64 encoded string.
curl -v -X GET \
-H 'Authentication: Basic <base64 encoded credentials>' \
-H 'Cache-Control: no-cache' \
-H 'Accept: application/json' \
-H "Content-Type: application/json" \
"https://<domain>.atlassian.net/wiki/rest/api/user/current"
> GET /wiki/rest/api/user/current HTTP/2
> Host: <domain>.atlassian.net
> User-Agent: curl/7.54.0
> Authentication: Basic <base64 encoded string>
> Cache-Control: no-cache
> Accept: application/json
> Content-Type: application/json
>
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 200
< server: Atlassian Proxy/0.1.205
< vary: Accept-Encoding
< cache-control: no-cache, must-revalidate
< content-type: application/json
< strict-transport-security: max-age=315360000; includeSubDomains; preload
< date: Thu, 22 Mar 2018 22:46:39 GMT
< expires: Thu, 01 Jan 1970 00:00:00 GMT
< x-xss-protection: 1; mode=block
< x-content-type-options: nosniff
<
* Connection #0 to host <domain>.atlassian.net left intact
{"type":"anonymous","profilePicture":{"path":"/wiki/s/<some path>/anonymous.png","width":48,"height":48,"isDefault":true},"displayName":"Anonymous","_expandable":{"operations":""},"_links":{"base":"https://<domain>.atlassian.net/wiki","context":"/wiki"}}