· 7 years ago · Jun 19, 2018, 09:22 PM
1function NSAuth(scriptID, type = 'post')
2 {
3 //Fall back authentication
4 return "NLAuth nlauth_account=4099054_SB1, nlauth_email=mwhite@whitelabs.com, nlauth_signature=Yeastman001, nlauth_role=3";
5
6 var time = Math.round(new Date().getTime()/1000);
7 var nonce = Utils.uuid();
8
9 var base = "deploy=1&oauth_consumer_key=" + system.NSAuthentication.consumerKey
10 + "&oauth_nonce=" + nonce
11 + "&oauth_signature_method=HMAC-SHA1"
12 + "&oauth_timestamp=" + time
13 + "&oauth_token=" + system.NSAuthentication.consumerToken
14 + "&oauth_version=1.0"
15 + "&script=" + scriptID.toString();
16
17 var encodedBase = type.toUpperCase() + "&" + encodeURIComponent('https://4099054-sb1.restlets.api.netsuite.com') + "&" + encodeURIComponent(base);
18 var baseSignature = system.NSAuthentication.consumerSecret + "&" + system.NSAuthentication.consumerTokenSecret;
19 var signature = encodeURIComponent(system.CryptoJS.HmacSHA1(encodedBase, baseSignature).toString(system.CryptoJS.enc.Base64));
20
21 var header = 'OAuth realm="4099054_SB1",'
22 + 'oauth_consumer_key="' + system.NSAuthentication.consumerKey + '",'
23 + 'oauth_token="' + system.NSAuthentication.consumerToken + '",'
24 + 'oauth_nonce="' + nonce + '",'
25 + 'oauth_timestamp="' + time + '",'
26 + 'oauth_signature_method="HMAC-SHA1",'
27 + 'oauth_version="1.0", '
28 + 'oauth_signature="' + signature + '"';
29
30 return header;
31 }