0

I work on a domain management software through the OVH's API. I use nodejs and node-webkit and I downloaded the official Node.js wrapper for OVH.

Then, I followed the documentation here: https://www.npmjs.com/package/ovh and here: https://eu.api.ovh.com/g934.first_step_with_api, and I came with the following code:

// set the ovh object with the right configuration
var ovh = require('ovh')({
  endpoint: 'ovh-eu',
  appKey: 'APP_KEY', // replace it with my key
  appSecret: 'APP_SECRET' // replace it with my key
});

ovh.request('POST', '/auth/credential', {
  // set access rules
  'accessRules': [
    {'method': 'GET', 'path': '/*'},
    {'method': 'POST', 'path': '/*'},
    {'method': 'PUT', 'path': '/*'},
    {'method': 'DELETE', 'path': '/*'},
  ]
}, function (error, credential) {
  // print the error if the request failed, else, print the response
  console.log(error || credential);
  // set the consumerKey in the ovh object
  ovh.consumerKey = credential.consumerKey;
  // connect on the credential.validationUrl to validate the consumerKey
  console.log(credential.validationUrl);

  testMe();
});


function testMe() {
  /*
    This fonction test a request every second
    to check if the user connected himself
  */
  ovh.requestPromised('GET', '/me')

    .then (function (me) {
      // if the user is connected, tell him welcome
      console.log('Welcome ' + me.firstname);
    }
  )
    .catch (function (err) {
      console.log(err);
      // while the user is not connected, retry the request
      setTimeout(testMe, 1000);
    }
  );
}

Well, when I execute this, everything is fine until I try to connect through the url, the testMe function keeps telling me an error and I don't get the welcome message.

In order to fix my problem, I tried to use different way to write my code and even checked in OVH's module sources if the signature was right before and after hashing, but it all seems to be good...

If someone already had this issue or if anybody see a error in my code, I would really appreciate your help. Thanks

  • Fixed! Look like i had a probleme when it generated my keys. But i regenerated it angain and it works !! –  Jul 04 '16 at 09:16

1 Answers1

0

you've got a syntax error :

then (function (response) {
      // if the user is connected, tell him welcome
      console.log('Welcome ' + me.firstname);
})

try this instead (renamed the parameter):

then (function (me) {
      // if the user is connected, tell him welcome
      console.log('Welcome ' + me.firstname);
})

Anyway, it it doesn't work properly please tell us the error you are getting.

richardtz
  • 4,993
  • 2
  • 27
  • 38
  • Thank you a lot for your answer! I fix it right now. Unfortunately, it don't resolve my problem, my console is always telling me the same error : "invalid signature" –  Jun 14 '16 at 13:10
  • can you check ovh.consumerKey is not empty? – richardtz Jun 14 '16 at 13:57
  • Yes, i made a 'console.log(ovh)' and the consumerKey appear in it, i checked it's validity with the graphical api at http://api.ovh.com/ and the key is write as a valid one. –  Jun 14 '16 at 14:21