Basic HTTP Authentication with Intel XDK

I am currently working with the Intel XDK and at the moment I am trying to integrate a personal rest API with my application.

I was able to set up the files the Intel XDK needs to recognize the API and I can already call methods on the Intel XDK Web Services tab.

My problem is that my application will need to require authentication from the user (username and password).

I've searched the internet for ways to do this and I believe HTTP Basic Authentication solves my problem, but I can't seem to implement this solution with Intel XDK.

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

PS - 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, if necessary please just let me know.

I should also mention that, like the feedback, Intel XDK is currently suffering from poor documentation and sample base, this 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"
  }
}
      

Run codeHide result


This is a .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;
})
      

Run codeHide result


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."
      }]
    }]
  }]
}
      

Run codeHide result


With these 3 I can make calls through the Intel XDK web services tab and create service bindings. Now I am trying to send username and password information via request header.

My main source of information for writing these files was this link https://github.com/mashery/iodocs . I tried experimenting with properties like Header and Auth in the apiconfig file and in the .js file.

+3


source to share


1 answer


Are you talking about this official decision? XDK setBasicAuthentication Method



0


source







All Articles