Error when trying to access a page through REST API. CORS?

Hi all.

I’m new here so I apologize if this post breaks any of the community rules in any way possible.

On to my problem.

I’m currently trying to create a jQuery page (in my Dev server) to read pages in my Confluence server. At first try, I was blocked the same origin policy, i.e. CORS. I decided to set Access-Control-Allow-Origin "*" in my Confluence server configuration and the problem was solved. Turns out this only solved the problem when reading pages that allow anonymous access. Another CORS error was raised when I add username and password to the ajax request in my jQuery page. However, the problem was soon solved by setting Access-Control-Allow-Headers "authorization, content-type" also in my Confluence server. The problem was only partially solved.

So at this point, I already set Access-Control-Allow-Origin and Access-Control-Allow-Headers in my Confluence server. From my jQuery page, I was able to read pages in my Confluence and send a valid credentials along with the request. Unfortanely, the pages that my jQuery page was able to read was still limited to pages open for anonymous access. I still can’t read pages that was limited to logged-on users.

I’ve checked the credentials and I’m certain they are valid. Whenever I send something random for the username or the password, my jQuery request was responded by a 401 error code which was authentication failed. So, I believe the source of the problem is not the credentials.

I’m still seeing this as a CORS issue, but I could be wrong. Is there something else that I should have done to solve my problem? Should I set more configuration to my Confluence server? If yes, what are those? Maybe it has something to do with the configuration inside Confluence application? If yes, which ones?

Any help or even pointers would be appreciated.

Thank you.