0

I'm trying to use the google chart api in an XPages application. I'm using the code example given by the documentation : https://developers.google.com/chart/interactive/docs/php_example#exampleusingphphtml-file

I have to replace the call to the php page by a call to an LS agent.

      var jsonData = $.ajax({
      url: "getData.php",
      dataType: "json",
      async: false
      }).responseText;

So my code goes to :

     var jsonData = $.ajax({
      url: "http://server/database/agent?openagent",
      dataType: "json",
      async: false
      }).responseText;

On my local domino server, it works fine. On the production domino server, I get nothing. The chart is not drawn. After debugging the js client side, it seems the ajax call is expecting an authentification even if I had to log in before.

The anonymous access is not allowed on both servers. The security level seems to be same on both environments

Any help will be welcome (or any other way to proceed if I'm wrong).

Thank you

Techn0fil
  • 65
  • 1
  • 5
  • Are you sure that Anonymous is not allowed to access http://server/database/agent?openagent on your local Domino server? Check the ACL of the database. Also, try accessing http://server/database/agent?openagent directly on both your local Domino server and on the production server. – Per Henrik Lausten Aug 18 '16 at 10:55
  • I've just checked the call of the agent on both servers. on the both servers, I have to log in before getting the agent results Anonymous entry is set as no access in LCA on both databases I tried also to implement the NetDeamon's solution, and no more results. – Techn0fil Aug 18 '16 at 11:52
  • 1
    If you want anonymous to be able to use the agent, you should give Anonymous the correct access in the ACL – Per Henrik Lausten Aug 18 '16 at 12:00
  • I don't need the anonymous access. I need to run the agent with the context of the user : the agent gets data for the current user. I will try to transform the call of the agent by a use of an Xpage. May be it will solve the issue. – Techn0fil Aug 18 '16 at 12:03

2 Answers2

0

If you are able to draw the google chart in your local server, but not in production server, this means it is your server issue.

You can add authentication header in your jquery ajax call to make authenticated ajax request

$.ajax({
  headers: {
    "Authorization": "Bearer <TOKEN HERE>" 
  }
})

You can also send username and password in jquery ajax call, to make authenticated request. Here is the sample code from the link

$.ajax({
    type: 'GET',
    url: 'url',
    dataType: 'json',
    //whatever you need
    beforeSend: function (xhr) {
        xhr.setRequestHeader('Authorization', make_base_auth(user, password));
    },
    success: function () {});
});

function make_base_auth(user, password) {
    var tok = user + ':' + password;
    var hash = btoa(tok);
    return 'Basic ' + hash;
}
Community
  • 1
  • 1
Netdeamon
  • 175
  • 2
  • 3
  • 9
  • hi, thanks for answering so quickly. unfortunately, the header of the ajax call does not work better. I think the result of the hash method is not what the domino server is expected as credentials I will continue to investigate – Techn0fil Aug 18 '16 at 11:53
  • What happens when you do login to your production server(through normal login page), and make the normal ajax call. Does it throw authentication error then? Passing the token or username/password in header of ajax call will work only if the server considers that, else it will not. – Netdeamon Aug 18 '16 at 12:16
0

at the end, I tried to run the ajax request through dojo instead of Jquery. My codes became this one :

var jsonData = dojo.xhrGet({
  url: "http://server/database/agent?openagent",
    handleAs:"json",
    ...
})  

I did no changes at the security level or anything else.

I do not understand why the jquery syntax is not working as well the dojo syntax.

anyway, it is working now.

Many thanks to all for your suggestions

Techn0fil
  • 65
  • 1
  • 5