This topic contains 3 replies, has 0 voices, and was last updated by pcutler 8 years, 3 months ago.
-
AuthorPosts
-
July 22, 2016 at 2:20 pm #6308
pcutlerHas anyone successfully implemented the code in SuiteAnswer 44020 (https://netsuite.custhelp.com/app/an…il/a_id/44020/) to post to a restlet from another script with token based authentication?
I copied the script exactly except for the following:
1. Updated token, token secret, consumer, and consumer secret
2. Updated account ID and restlet URL
Then I created a suitelet in the same account as an existing restlet with the script file and applied the hmac-sha1.js and oauth-1.0a.js files linked from the SuiteAnswer as libraries. When I run the Suitelet, the response is {“error” : {“code” : “INVALID_LOGIN_ATTEMPT”, “message” : “Invalid login attempt.”}}. If I search the login audit trail, the detail for the failed login says “signature_invalid.”
Side note – the script runs successfully if I replace the authorization header with an NLAuth header.
Anything I’m obviously missing? Any tips for debugging?
This is a cached copy. Click here to see the original post. -
July 22, 2016 at 2:28 pm #6309
david.smithMake sure you have unique values every time for the oauth_nonce and timestamp. It looks to me like the call to oauth.getNonce(), and oauth.getTimeStamp(), are missing from this code.
-
July 22, 2016 at 2:37 pm #6310
pcutlerThanks for the tip. I believe the reason we don’t see those two calls in NetSuite’s code is because they’re inside the authorize method in the oauth library.
NetSuite’s code calls .authorize:
var headerWithRealm = oauth.toHeader(oauth.authorize(request_data, token));
And the authorize method contains those two calls:
OAuth.prototype.authorize = function(request, token) {
var oauth_data = {
oauth_consumer_key: this.consumer.public,
oauth_nonce: this.getNonce(),
oauth_signature_method: this.signature_method,
oauth_timestamp: this.getTimeStamp(), …
Based on my logging, I can confirm that new values are generated on each run.
-
July 26, 2016 at 1:36 pm #6311
pcutlerNetSuite support provided the answer – I was missing one library file. It now logs in successfully with the following three libraries (in this order):
oauth-1.0a.js
hmac-sha1.js
enc-base64.js
k_dunc replied on 07/26/2016, 06:33 PM: Thanks for sharing.
-
AuthorPosts
You must be logged in to reply to this topic.