KnotKnick
06/01/2021, 8:49 PMbattk
06/01/2021, 8:51 PMbattk
06/01/2021, 8:51 PMbattk
06/01/2021, 8:51 PMKnotKnick
06/01/2021, 9:24 PMbattk
06/01/2021, 9:26 PMKnotKnick
06/01/2021, 9:28 PMbattk
06/01/2021, 9:28 PMbattk
06/01/2021, 9:29 PMKnotKnick
06/01/2021, 9:42 PMheaders like this Basic thisismybase64?battk
06/01/2021, 9:43 PMbattk
06/01/2021, 9:44 PMKnotKnick
06/01/2021, 9:45 PMMTNathan
06/02/2021, 3:10 PMcustsecret_my_secret, the header should literally include that as a string in brackets like so: {Authorization:'Basic {custsecret_my_secret}'}? If it makes a difference, this is for a get request using https.get(), and I'm passing that object in as the headers option.battk
06/02/2021, 3:13 PMMTNathan
06/02/2021, 3:35 PMvar apiToken = 'API_TOKEN_GOES_HERE';
var apiTokenBase64 = encode.convert({
'string':apiToken + ':api_token',
'inputEncoding':encode.Encoding.UTF_8,
'outputEncoding':encode.Encoding.BASE_64
});
var apiResponse = https.get({
'url':'URL_GOES_HERE',
'headers':{Authorization:'Basic ' + apiTokenBase64}
});
And here's what I'm trying that's not working:
var apiResponse = https.get({
'url':'URL_GOES_HERE',
'headers':{Authorization:'Basic {custsecret_my_secret}'}
});
Where the secret with the id custsecret_my_secret is a base 64 encoded string from API_TOKEN_GOES_HERE:api_token.battk
06/02/2021, 3:36 PMMTNathan
06/02/2021, 3:50 PMhttps.get()? The only options I see documented are url and headers (https://system.netsuite.com/app/help/helpcenter.nl?fid=section_4567631366.html). If it is available in https.get(), what would I include at that point? Useful examples in the documentation are rather sparse...battk
06/02/2021, 3:58 PMbattk
06/02/2021, 3:59 PMbattk
06/02/2021, 4:00 PMMTNathan
06/02/2021, 4:04 PM<http://https.post|https.post> and https.request only mention that credentials does the replacement in the body - does it also work for headers despite the explicit mention?battk
06/02/2021, 4:04 PMbattk
06/02/2021, 4:04 PMMTNathan
06/02/2021, 4:07 PMnsdev0001
06/02/2021, 6:19 PMnsdev0001
06/02/2021, 6:20 PMMTNathan
06/02/2021, 6:24 PMnsdev0001
06/02/2021, 6:42 PMnsdev0001
06/02/2021, 6:43 PMvar secureToken = https.createSecureString({
input: '{' + 'custsecret_connector_pd' + '}'
});
var bodydata = {
"grant_type": "client_credentials",
"client_id": clientId,
"client_secret": secureToken
};
var response = <http://https.post|https.post>({
url: procoreAuthorizeURL,
body: bodydata
});MTNathan
06/02/2021, 7:37 PMvar secureString = https.createSecureString({input:'{custsecret_my_secret}'});
var apiResponse = https.get({
url:'URL_GOES_HERE',
credentials:['{custsecret_my_secret}'],
headers:{Authorization:'Basic ' + secureString}
});
Where the secret with id custsecret_my_secret is the base64 encoded value of API_TOKEN_GOES_HERE:api_token. I've also tried it without the braces in the credentials option, and with encoding specified as https.Encoding.BASE_64 in the https.createSecureString() call, none of those worked. I'm at a loss for what else to try, I'm open to any suggestions you may have based on what I've tried so far.nsdev0001
06/02/2021, 8:05 PMnsdev0001
06/02/2021, 8:07 PMMTNathan
06/02/2021, 8:16 PMnsdev0001
06/02/2021, 8:24 PMbattk
06/02/2021, 9:34 PM'Basic ' + secureString
is not a secure stringbattk
06/02/2021, 9:35 PMbattk
06/02/2021, 9:37 PMnsdev0001
06/02/2021, 9:39 PMbattk
06/02/2021, 9:42 PMbattk
06/02/2021, 9:42 PMbattk
06/02/2021, 9:46 PM/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope SameAccount
*/
define(["N/crypto", "N/encode", "N/https", "N/sftp", "N/file"], function (
crypto,
encode,
https,
sftp,
file
) {
return {
onRequest: function doSecret(context) {
var secureToken = https.createSecureString({
input: "{" + "custsecret_connector_pd" + "}",
});
var clientId = "iBlameKnotKnickForLearningInDmInsteadOfPublic";
var bodydata = {
grant_type: "client_credentials",
client_id: clientId,
client_secret: secureToken,
};
var response = <http://https.post|https.post>({
url: "<https://www.httpbin.org/post>",
body: bodydata,
});
context.response.write(response.body);
},
};
});battk
06/02/2021, 9:50 PMMTNathan
06/02/2021, 9:55 PMBasic BASE_64_ENCODED_DATA_HERE and the rest should look like this:
var secureString = https.createSecureString({input:'{custsecret_my_secret}'});
var apiResponse = https.get({
url:'URL_GOES_HERE',
credentials:['custsecret_my_secret'],
headers:{Authorization:secureString}
});
Does that align with what you'd expect? It seems to be working for me now but that was admittedly a very quick and dirty test.battk
06/02/2021, 9:56 PMbattk
06/02/2021, 9:56 PMMTNathan
06/02/2021, 9:57 PMcredentials option isn't necessary in the get call at that point.battk
06/02/2021, 9:57 PMbattk
06/02/2021, 9:58 PMMTNathan
06/02/2021, 9:58 PMbattk
06/02/2021, 10:02 PMMTNathan
06/02/2021, 10:02 PMvar secureString = https.createSecureString({input:'Basic {custsecret_my_secret}'});
var apiResponse = https.get({
url:'URL_GOES_HERE',
headers:{Authorization:secureString}
});
Hopefully you can get it from there as well.battk
06/02/2021, 10:03 PM"Basic {custsecret_connector_pd}"battk
06/02/2021, 10:03 PMvar secureToken = https.createSecureString({
input: "Basic {custsecret_connector_pd}",
});battk
06/02/2021, 10:04 PMbattk
06/02/2021, 10:05 PMbattk
06/02/2021, 10:08 PMbattk
06/02/2021, 10:09 PMMTNathan
06/02/2021, 10:12 PMN/encode module on just the piece that needs to be encoded rather than rely on the SecureString methods, but storing the encoded string in the secret seems to be the most straightforward option.MTNathan
06/02/2021, 10:12 PMbattk
06/02/2021, 10:14 PMbattk
06/02/2021, 10:14 PMbattk
06/02/2021, 10:14 PMMTNathan
06/02/2021, 10:21 PMnsdev0001
06/02/2021, 11:14 PM