1 2 Previous Next 16 Replies Latest reply on Apr 20, 2017 10:09 AM by Marco Monti

    Teiid: User authentication for oData v4 query via javascript

    Marco Monti Newbie

      Hi everybody,

       

      I am trying to query a Teiid entity using oData v4 via javascript using following code:

       

                  $.ajax({

                      type: 'GET',

                      url: 'http://server/odata4/VDB.1/Model/Entity?$format=JSON',

                      dataType: 'json',

                      beforeSend: function (xhr) {

                          xhr.setRequestHeader("Authorization", "Basic " + btoa("username:password"));

                      }

                  })

                  .done(function (result) {

                      $.each(result.value, function () {

                          $("#mySelect").append($("<option />").val(this.EntityID).text(this.EntityDescription));

                      });

                  })

                  .fail(function () {

                      $("#mySelect").append($("<option />").val("0").text("ERROR ..."));

                  });

       

      I also tried using the datajs 1.1.3 library (https://datajs.codeplex.com/):

       

                  OData.read(

                      {

                          headers: {},

                          requestUri: 'http://server/odata4/VDB.1/Model/Entity?$format=JSON',

                          method: 'POST',

                          data: {},

                          user: 'username',

                          password: 'password'

                      },

                      function (data, response) {

                          $.each(data.value, function () {

                              $("#mySelect").append($("<option />").val(this.EntityID).text(this.EntityDescription));

                          });

                      },

                      function (err) {

                          $("#mySelect").append($("<option />").val("0").text("... " + err.message + " ..."));

                      });

       

      In both cases I get an authentication error.

       

      I also tried to query the reference oData v4 service at http://services.odata.org/V4/Northwind/Northwind.svc (which doesn't require any authentication, so I didn't specify the beforeSend attribute) and the $.ajax() query worked like a charm.

       

      Can you please help me solve this problem? Thank you in advance for any reply.

       

      Regards,

      Marco

        1 2 Previous Next