Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Invalid signature error only from module exports. #3

Closed
bugs181 opened this issue Jan 14, 2014 · 4 comments
Closed

Invalid signature error only from module exports. #3

bugs181 opened this issue Jan 14, 2014 · 4 comments

Comments

@bugs181
Copy link

bugs181 commented Jan 14, 2014

To further explain the issue, if I call yelp.search() from within the module, everything works out and I receive data. However if I call that very same function using module.exports function I receive an invalid signature error.

Error:

{"error": {"text": "Signature was invalid", "id": "INVALID_SIGNATURE", "description": "Invalid signature. Expected signature base string: GET\u0026http%3A%2F%2Fapi.yelp.com%2Fv2%2Fsearch\u0026location%3DReno%252C%2520NV%26oauth_consumer_key%3D_removed_%26oauth_nonce%3D_removed_%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1389681156%26oauth_token%3D_removed_%26oauth_version%3D1.0%26term%3D"}}

Here is my code.

var yelp = require("yelp").createClient({
  consumer_key: "my_consumer_key", 
  consumer_secret: "my_consumer_secret",
  token: "my_token",
  token_secret: "my_token_secret"
});

module.exports = {
  search: function(req, res, callbacker) {

    // Does not work and throws Invalid Signature error
    yelp.search({term: "", location: "Reno, NV"}, function(error, data) {
      if (data)  console.log(data);
    });

  }
}

// Works as expected here.
yelp.search({term: "", location: "Reno, NV"}, function(error, data) {
    if (data)  console.log(data);
});

What could the issue be?

@bugs181
Copy link
Author

bugs181 commented Jan 14, 2014

Also, to note. If I just wrap yelp.search() in another function (outside module.exports) and call that from module.exports->search(), it still throws the error.

@bugs181
Copy link
Author

bugs181 commented Jan 15, 2014

Found the issue. This is why you shouldn't mess with the prototypes boys and girls. ;)

Apparently oath is very strict about the typeof something.

Object.prototype.typeof = function(object) {
  if (!object) { object = this }

  if (typeof(object) === "object" && 'splice' in object && 'join' in object) {
    return 'array';
  }

  return typeof(object);
}

@bugs181 bugs181 closed this as completed Jan 15, 2014
@bugs181
Copy link
Author

bugs181 commented Jan 15, 2014

Actually, this is an oauth issue. Any time the object.prototype is modified, oauth throws that error.

ciaranj/node-oauth#174

@olalonde
Copy link
Owner

Thanks for pointing this out.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants