I'd like to parse a string given by : http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/people but my code doesn't log in alfresco.
Thus, I wrote this code in my custom share page:
So, this gives me a basic 401 console error about the authentification
:8080/alfresco/api/-default-/public/alfresco/versions/1/people Failed to load resource: the server responded with a status of 401 (Unauthorized)
new-page:1 XMLHttpRequest cannot load http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/people. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access. The response had HTTP status code 401.
Besides, when I go on http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/people the basic login pop-up opens in which I can log in with admin/admin and get the expected result:
If anyone knows where is my mistake thanks in advance !
I'm bit puzzled by the message about port 8081 but you could try to enable cors in the web.xm of alfresco like described in the configuration for the alfresco ng-components: alfresco-ng2-components/ALFRESCOCORS.md at master · Alfresco/alfresco-ng2-components · GitHub
Maybe this helps...
The port 8081 is because I used Maven to create my Alfresco repository and Share too. So Alfresco is running on 8080 and Share on 8081. So I've looked into enabling CORS in an Alfresco repo generated by Maven previously but it doesn't really work I think, the web.xml aren't the same, when I add the lines missing to enable CORS it bugs the compilation and so on...
But since Share works properly during the normal use I don't think that the CORS are the problem ? I don't know..
...but you are starting the XMLHttprequest from the html page - that means from your browser - if I understood the problem.
There is also the enablecors platform module JAR (see the above link) - maybe you can include this to your repo...
Ok I've seen with someone how to enable CORS in project. So I added these lines into my Alfresco repo (and put the lines in the web.xml such as said in the github link, and added the jar wherever I could or seemed right aha) :
<!-- Enabling CORS -->
<!-- End enabling CORS -->
But I still get the same problems..
I was also wondering since I'm creating a new page in Share do I have to add lines into the configurations xml files of this page to access the Alfresco database ? My xml files only contain :
The problem isn't related to CORS. You say "custom share page" - which means you should be calling all Alfresco APIs through the Share proxy to piggy-back onto the existing authentication that Share is already using. You are trying to call Alfresco server directly, which is a bad idea from Share - as you have no idea what authentication chain is being used etc.
To call that API through Share and get the result is simply a matter of changing the GET URL:
That will return the result you want, it will also use the existing authentication for the logged in Share user.
I was wondering, I have an Apache2 server running on a Raspberry Pi, so I wanted to know if the same page I'm working on could work. But there is no share proxy. so I used the code I made at the beginning to access the api
people.open('GET', 'http://192.168.1.103:8080/alfresco/api/-default-/public/alfresco/versions/1/people', true, 'admin', 'admin');
But this doesn't work (as kinda expected).
So how am I supposed to access alfresco from another instance than Share ?