New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot make POST request #9
Comments
Anyone? I used the LinkedIn OAuth verification test console (https://developer.linkedin.com/oauth-test-console) to see if the signatures match with my POST request, but they don't... :/ I am sure all my keys, access tokens etc are correct. Using Apigee, I can successfully send a message, so maybe the OAuth library is bugged? Can someone look into this issue? :) |
Hi @philipdesmedt, have you fixed that? thanks! |
Yes, I did fix it, but it's a (kind of ugly) hack. Let me quickly explain. I might do a pull request if I've got some time the next few days. Basically, the included OAuth library doesn't work as it should with POST requests. So, I wanted to keep using this API wrapper and make POST requests as well. After a while, I noticed the OAuth library just did not work with POST requests, as it generated the wrong authorization 'string' (which is a combination of a consumer key, nonce, signature method, timestamp, token, version and signature). I implemented the authorization and signature method myself and passed this to the linkedin-js wrapper. I used the following code:
I used the above methods to generate the authorization and signature strings. The code to send the message through linkedin itself looked something like this:
In the above, the linkedin object is just an instance of this linkedin library. As you can see, I pass an HTTP method, a URL, parameters and callback. The parameters include the authorization string. Ok... almost there. Next I modified the linkedin-js library itself to intercept this authorization string and - if not null - use it instead of the authorization string it generates. Still following? 👍 In linkedin_client.js, starting from line 75:
As you can see, here I caught the authorization string and I JSON stringified the mailbox-item immediately (normally params should already be a JSON object, I guess). Another reason I didn't do a pull request... my solution only worked for mailbox items now, since I hardcoded that. Oh well. Finally, in /linkedin-js/node_modules/oauth/lib/oauth.js, I changed quite a few methods:
As you can see, I added the authorization string as a parameter to these methods and changed each method call all the way up to _performSecureRequest, where I did an (authorization === undefined) check. If it was undefined, I just calculated it using _buildAuthorizationHeaders, else I used the one that I calculated myself and generated. I probably spend hours and hours looking at this and in the end I was quite desperate, so that's why I tried calculating my own authorization string. Still a wonder that this worked. I'm not proud of the solution and I should've changed it once I noticed that this worked, but I guess other functionality was more important at that time. A better (read: no monkey patching) solution would have been to contact @masylum and replace the OAuth library itself, so POST requests work again. AFAIK, that is the solution. I'm not sure if this project is still under maintenance though. If you've got other questions, feel free to ask and I'll try to respond in a timely manner. |
Thanks a lot! 2013/3/19 Philip De Smedt notifications@github.com
|
Guys, may you help me, I am trying to make it work, so thank you very much for your posts, very self-explanatory. But I am stuck with the line, which contains OAuth.timestamp(). Node says object OAuth doesn't have this method. I thought OAuth = require('oauth').OAuth, but it doesn't seem to be true. What is that magic OAuth variable? |
Hi Igor, i hope it fixes your problem, Juan 2013/4/11 Igor Pavlov notifications@github.com
|
Thanks, I will try it! |
When making a POST request (i.e. sharing something or trying to send a message), I get a 401 error:
error: [Messaging] error: { statusCode: 401,
data: '\n\n 401\n 1336572233851\n Q9YREZSZ2Z\n 0\n [unauthorized]. OAU:blablabla (token etc)=\n\n' }
When trying to do a GET request, everything goes fine (i.e. getting my connections). Here is the code for the POST request:
I don't know if this is a real issue (i.e. bug) with the library or something else is wrong. The token and secret definitely work (get the same error when I hard-code them unencrypted). Someone who knows what's wrong?
The text was updated successfully, but these errors were encountered: