thallium205 / xero

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

Signature invalid - failed to validate signature #19

Open diptenagile opened 8 years ago

diptenagile commented 8 years ago

I generated private/public key pair 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

and create private app using publickey.cer file and pass private key in configuration :

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));
});

I also tried to to pass RSA_PRIVATE_KEY directly in xero config. But still i facing { statusCode: 401, data: 'oauth_problem=signature_invalid&oauth_problem_advice=Failed%20to%20validate%20signature' }

Please help me. Thanks.

ryardley commented 8 years ago

+1

benbowes commented 8 years ago

The below setup is working for me... could it be that you need to use ./privatekey.pem or './cert/privatekey.pem' --- so ./ before your file name ?

var Xero = require('xero');

var CONSUMER_KEY = 'SOME_KEY';
var CONSUMER_SECRET = 'SOME_SECRET';
var RSA_PRIVATE_KEY = require('fs').readFileSync('./cert/privatekey.pem');

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

xero.call('GET', '/Users', null, function(err, json) {
  if (err) {
    return console.log('Error', err);
  }
  return console.log('json', json);
});
benbowes commented 8 years ago

@FreakDroid if I understand your question correctly.

Look into one of these links:

Mac: https://rietta.com/blog/2012/01/27/openssl-generating-rsa-key-from-command/

PC: https://support.rackspace.com/how-to/generating-rsa-keys-with-ssh-puttygen/

Also consider the security perspective.

FreakDroid commented 8 years ago

@benbowes Hi again, thanks for you help.

But now I have another question, after you create the public and private key, How do you upload the publickey in the Xero's server for the autentication??? Because If I understand good, that is necesary for Xero to autenticate you, or I'm complete misunderstand the docs.

Thanks.

benbowes commented 8 years ago

Hi @FreakDroid

You need to upload your certificate or should I say contents of the certificate.

I placed mine in a folder called cert at the root of the directory and I added the files also to my .gitignore file :)