ehcanadian
07/19/2021, 8:10 PMN/https
and N/crypto
be used to create a basic auth header without using a guid but using the username/pass stored in API Secrets? I don't see how to retrieve the password to add it to credentials
in <http://https.post|https.post>
Clay Roper
07/19/2021, 8:11 PMehcanadian
07/19/2021, 8:13 PMBasic base64encodedString
Clay Roper
07/19/2021, 8:15 PMbattk
07/19/2021, 8:21 PMbattk
07/19/2021, 8:21 PMbattk
07/19/2021, 8:22 PMbattk
07/19/2021, 8:23 PMBasic
part of the authorization headerbattk
07/19/2021, 8:23 PMehcanadian
07/19/2021, 8:24 PMcreateSecret
and using that for secureString?ehcanadian
07/19/2021, 8:24 PMehcanadian
07/19/2021, 8:25 PMvar username_credential = GLOBALS.Constants.credentials.username;
var password_credential = GLOBALS.Constants.credentials.token;
var credentials = [username_credential, password_credential];
var secureString1 = https.createSecureString({
input: '{' + username_credential + '}'
});
secureString1.appendString({
input: ':',
encoding: https.Encoding.UTF_8
});
var secureString2 = https.createSecureString({
input: '{' + password_credential + '}'
});
secureString1.appendSecureString({
secureString: secureString2
});
secureString1.convertEncoding({
toEncoding: https.Encoding.BASE_64
});
var headers = {};
headers['authorization'] = secureString1; //getCredentialHeader4();
log.debug('POSTING RECORD', JSON.stringify(recordObject));
// send data
try {
var restResponse = <http://https.post|https.post>({
headers: headers,
credentials: credentials,
body: JSON.stringify(recordObject),
url: endpoint
});
} catch (e) {
log.error('ERROR POSTING RECORD', e);
return null;
}
ehcanadian
07/19/2021, 8:25 PMbattk
07/19/2021, 8:26 PMbattk
07/19/2021, 8:27 PMehcanadian
07/19/2021, 8:27 PMehcanadian
07/19/2021, 8:49 PMAllow all domains
seems busted on the secrets page, I keep getting an error of INVALID_DOMAIN no matter what I do there.battk
07/19/2021, 9:44 PMehcanadian
07/19/2021, 9:52 PM/**
* @NApiVersion 2.1
* @NScriptType Suitelet
*/
define(['N/https', 'N/crypto'],
/**
* @param{https} https
*/
(https, crypto) => {
const onRequest = (scriptContext) => {
let output = '';
if (scriptContext.request.method === 'GET') {
let secret = 'custsecretac7e387eb41c4699a9dc55ec35d78ea6';
const secretKey = https.createSecretKey({
secret: secret
});
let post_url = '<https://webhook.site/baa3e55c-9a5b-4790-9c5b-3eb7f2bebf99>';
const username_credential = secret.replace('custsecret', '');
const password_credential = secretKey.secret;
const credentials = [username_credential, password_credential];
let secureString1 = https.createSecureString({
input: '{' + username_credential + '}'
});
secureString1.appendString({
input: ':',
encoding: https.Encoding.UTF_8
});
const secureString2 = https.createSecureString({
input: '{' + password_credential + '}'
});
secureString1.appendSecureString({
secureString: secureString2
});
secureString1.convertEncoding({
toEncoding: https.Encoding.BASE_64
});
const headers = {};
headers['authorization'] = secureString1;
const postdata = {
'other': 'placeholder information'
};
output += 'postdata = ' + JSON.stringify(postdata, null, 3); //output postdata in suitelet
// send data
try {
var response = <http://https.post|https.post>({
headers: headers,
credentials: credentials,
body: postdata,
url: post_url
});
output += '\n\nresponse = ' + response.body; //output response
} catch (e) {
log.error('ERROR', e);
scriptContext.response.write(`Error: ${e.message}`);
return;
}
}
scriptContext.response.write(output);
}
return {onRequest}
});
battk
07/19/2021, 9:54 PMbattk
07/19/2021, 9:54 PMehcanadian
07/19/2021, 9:55 PMbattk
07/19/2021, 9:55 PMlet secret = 'custsecretac7e387eb41c4699a9dc55ec35d78ea6';
const secretKey = https.createSecretKey({
secret: secret
});
const username_credential = secret.replace('custsecret', '');
battk
07/19/2021, 9:55 PMehcanadian
07/19/2021, 9:56 PMehcanadian
07/19/2021, 9:56 PMehcanadian
07/19/2021, 9:57 PMbattk
07/19/2021, 9:59 PMbattk
07/19/2021, 9:59 PMbattk
07/19/2021, 10:00 PMehcanadian
07/19/2021, 10:07 PMehcanadian
07/19/2021, 10:07 PMbattk
07/19/2021, 10:10 PMbattk
07/19/2021, 10:10 PMbattk
07/19/2021, 10:10 PMbattk
07/19/2021, 10:10 PMehcanadian
07/19/2021, 10:11 PMbattk
07/19/2021, 10:12 PMbattk
07/19/2021, 10:13 PMehcanadian
07/19/2021, 10:29 PMehcanadian
07/19/2021, 10:30 PMbattk
07/19/2021, 10:38 PMbattk
07/19/2021, 10:39 PMconst username_credential = secret.replace('custsecret', '');
ehcanadian
07/20/2021, 2:50 AMbattk
07/20/2021, 3:01 AMbattk
07/20/2021, 3:03 AMehcanadian
07/20/2021, 3:03 AMehcanadian
07/20/2021, 3:03 AMehcanadian
07/20/2021, 3:03 AMehcanadian
07/20/2021, 3:04 AMbattk
07/20/2021, 3:04 AMehcanadian
07/20/2021, 3:04 AMehcanadian
07/20/2021, 3:06 AMbattk
07/20/2021, 3:06 AMehcanadian
07/20/2021, 3:06 AMbattk
07/20/2021, 3:07 AMbattk
07/20/2021, 3:07 AMehcanadian
07/20/2021, 3:08 AMehcanadian
07/20/2021, 3:08 AM