Saturday, 13 May 2017

Basic authentication not working in node-rest-client node

I'm using node-rest-client library to call my rest API running a python flask app in a test server. The Node setup and request code is below.

If I add a user token to the request header it words fine, but in the call to obtain the user token using basic auth my python system is successfully authenticating and returning the token with a 200 status, but the flask server is then changing this to a 400 Bad Request. It works fine making the call using Postman.

Is there something missing from my two config objects for node-rest-client?

Cheers.

var options_auth = { 
    user: "bob", 
    password: "password",
    mimetypes: {
        json: ["application/json", "application/json;charset=utf-8"]
    } 
};

var Client = require('node-rest-client').Client;
var client = new Client(options_auth);
var method = "/authtoken";

var args = {
    headers: { 
        "Content-Type": "application/json",
        "api-key": "asf89a7assa98d7sd98d98ds",
        //"token": "dsf98s7dsf98dsf7sd98f7dsf",
        "Accept": "application/json"
    },
    responseConfig: {
        timeout: 1000 //response timeout
    }
};

client.get(Api.url+method, args, function (data, response) {
    // parsed response body as js object 
    // raw response 
    //console.log(response);

    if(Buffer.isBuffer(data)){
        data = data.toString('utf8');
    }
    console.log(data);

    var stringData = data.toString('utf8');

    console.log("String data = "+stringData);

}).on('error', function (err) {
    console.error('Something went wrong with the http client', err);
});



via Jon

No comments:

Post a Comment