This topic contains 3 replies, has 0 voices, and was last updated by pcutler 7 years, 8 months ago.

  • Author
    Posts
  • #6308 Score: 0

    pcutler
    • Contributions: 0
    • Level 1

    Has 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.

  • #6309 Score: 0

    david.smith
    • Contributions: 0
    • Level 1

    Make 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.

  • #6310 Score: 0

    pcutler
    • Contributions: 0
    • Level 1

    Thanks 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.

  • #6311 Score: 0

    pcutler
    • Contributions: 0
    • Level 1

    NetSuite 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.

You must be logged in to reply to this topic.