thallium205 / xero

Xero Library for Private Applications in Node
48 stars 55 forks source link

Signature Invalid (signature_invalid) #3

Closed oitozero closed 10 years ago

oitozero commented 10 years ago

Getting an OAuth error when trying to run the request example.

Here are my steps:

Created a Xero Private application. Generated public/private certs using:

openssl genrsa -out privatekey.pem 1024
openssl req -new -x509 -key privatekey.pem -out publickey.cer -days 1825
openssl pkcs12 -export -out public_privatekey.pfx -inkey privatekey.pem -in publickey.cer

Uploaded public key certificate (publickey.cer). Obtained consumer key/secret. Tested sample https://github.com/thallium205/xero#request. Getting following error:

{ statusCode: 401,
  data: 'oauth_problem=signature_invalid&oauth_problem_advice=Failed%20to%20validate%20signature' }

What am I missing here?

Thanks.

oitozero commented 10 years ago

The issue was with reading the private key.

var Xero = require('xero');

var CONSUMER_KEY = '...';
var CONSUMER_SECRET = '...';
var RSA_PRIVATE_KEY = require('fs').readFileSync('privatekey.pem');

var xero = new Xero(CONSUMER_KEY, CONSUMER_SECRET, RSA_PRIVATE_KEY);

xero.call('GET', '/Users', null, function(err, json) {
    if (err) {
        console.error(err);
    }
    console.log('response:' + JSON.stringify(json));
});
diptenagile commented 8 years ago

I tried with

var RSA_PRIVATE_KEY = require('fs').readFileSync('privatekey.pem');

var xero = new Xero(CONSUMER_KEY, CONSUMER_SECRET, RSA_PRIVATE_KEY);

and also tried with passing .pem key as a RSA_PRIVATE_KEY but still facing { statusCode: 401, data: 'oauth_problem=signature_invalid&oauth_problem_advice=Failed%20to%20validate%20signature' }