not able to call a restfull method

19 views
Skip to first unread message

Rajeev Kumar

unread,
Jun 2, 2015, 9:46:08 AM6/2/15
to nod...@googlegroups.com
Hi,

I am trying to write a client program to call a restfull GET with Basic authorization but it is giving 401 error (unauthorized client).

below is piece of code i am using:

var http = require('http');
var options = {
  host: 'taken.generate.url',
  port: 38080,
  path: 'oauth2-api/p/v1/token?scope=TMO_ID_profile%20associated_lines%20token_validation%20iam_account_lock_information%20billing_information%20permission%20offer&grant_type=client_credentials',
  authorization: 'Basic VHJ1c3RlZENsaWVudENSMjQ6enJCamZ6cWdESw==',
  method: 'GET'
};

http.request(options, function(res) {
  console.log('STATUS: ' + res.statusCode);
  console.log('HEADERS: ' + JSON.stringify(res.headers));
  res.setEncoding('utf8');
  res.on('data', function (chunk) {
    console.log('BODY: ' + chunk);
  });
}).end();

-------------------------------

when i am using shell script ,I am able to achieve this with success 200.

 $ curl -i -H 'Authorization: Basic VHJ1c3RlZENsaWVudENSMjQ6enJCamZ6cWdESw==' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Accept: application/json' -X GET 'http://<IPADRRESS>:38080/oauth2-api/p/v1/token?scope=TMO_ID_profile%20associated_lines%20token_validation%20iam_account_lock_information%20billing_information%20permission%20offer&grant_type=client_credentials'


Please suggest where I am doing mistake in node.js file.

Thanks

Aria Stewart

unread,
Jun 2, 2015, 10:08:01 AM6/2/15
to nod...@googlegroups.com

> On Jun 2, 2015, at 2:36 AM, Rajeev Kumar <gane...@gmail.com> wrote:
>
> Hi,
>
> I am trying to write a client program to call a restfull GET with Basic authorization but it is giving 401 error (unauthorized client).
>
> below is piece of code i am using:
>
> var http = require('http');
> var options = {
> host: 'taken.generate.url',
> port: 38080,
> path: 'oauth2-api/p/v1/token?scope=TMO_ID_profile%20associated_lines%20token_validation%20iam_account_lock_information%20billing_information%20permission%20offer&grant_type=client_credentials',
> authorization: 'Basic VHJ1c3RlZENsaWVudENSMjQ6enJCamZ6cWdESw==',
> method: 'GET'
> };

authorization is not an option to the http library, but a header you send. Try

headers: {
Authorization: 'Basic VHJ1c3RlZENsaWVudENSMjQ6enJCamZ6cWdESw=='
},

in the options.

Also, please note that those credentials should have been throw-away ones. Decoded they are TrustedClientCR24:zrBjfzqgDK. You'll need to replace those credentials since they're compromised.

Aria
Reply all
Reply to author
Forward
0 new messages