3

I'm currently working with Intel XDK and at this moment I'm trying to integrate a personal rest API with my app.

I managed to configure the files that are necessary for Intel XDK to recognize the API and I'm already able to call the methods within the Intel XDK Web Services' Tab.

My problem is that my app will have to require authentication from the user ( user name and password ).

I searched on the web ways of doing it and I believe that HTTP Basic Authentication solves my problem, but I'm not being able to implement this solution with Intel XDK.

So I'm looking for examples or anything that could help me achieve that (Basic Http Authorization with Intel XDK)... to be able to send the authorization within the request header.

P.S - I didn't show the config files I have now because I don't think they will add any value to the question, but there is no problem to do that if it's necessary, please, just let me know.

I should also mention, just as a feedback, that Intel XDK is currently suffering from poor documentation and sample base, these can certainly be improved a lot.

This is the apiconfig.json file

{
  "API": {
    "name": "API Name",
    "description": "API description.",
    "protocol": "rest",
    "basePath": "The base path to my API",
    "basicAuth": "true"
  }
}

This is the .js file

(function(credentials, helpers) {
  var exports = {};

  exports.GetEstoque = function(params) {
    var url = 'URL to this methods enpoint';
    params["apiKey"] = credentials.apiKey;
    if (params) url = url + '?' + $.param(params);
    return $.ajax({
      url: url,
      type: 'GET'
    });
  };
  return exports;
})

This is the .json file

{
  "endpoints": [{
    "name": "Estoque",
    "dashboardUrl": "DashboardUrl",
    "methods": [{
      "MethodName": "GetEstoque",
      "Synopsis": "Retorna informação de estoque por filial",
      "parameters": [{
        "Name": "CodigoFilial",
        "Required": "Y",
        "Default": "",
        "Type": "string",
        "Description": "Código da filial da qual o estoque será retornado."
      }]
    }]
  }]
}

With those 3 I'm able to make calls through the Intel XDK Web Services' tab and to create Service Bindings as well. Now I'm trying to send information about username and password through the request header.

My main source of information to write those files was this link https://github.com/mashery/iodocs. I tried to experiment with properties such as Header and Auth in the apiconfig file and on the .js file.

  • I'm not 100% sure. Could you provide a small sample of what you've tried? E.g. JS code. Appreciate the feedback about documentation, we're working on improving that. – OldGeeksGuide Aug 06 '15 at 23:35
  • @OldGeeksGuide thanks for the reply, I added some more detailed information. –  Aug 10 '15 at 14:41
  • I don't see where you're passing the `username` and `password`. If I understand correctly, current versions of jQuery recognize these as options in the object passed in the `$.ajax` call (cf. http://stackoverflow.com/a/11960692 ). Have you tried that? Or am I confused about how you're doing things? – OldGeeksGuide Aug 10 '15 at 21:59

1 Answers1

0

Are you talking about this official solution? XDK setBasicAuthentication Method

Zappescu
  • 1,369
  • 2
  • 9
  • 24