hey everyone! Does anyone have experience using t...
# suitescript
m
hey everyone! Does anyone have experience using the new "API Secrets" with the N/https module? I'm trying to store Basic auth client/secret credentials in a "Secret" and then use it in a SecureString, but it doesn't seem to be that simple of course.
b
are you on 2021.2?
m
not yet, why?
b
2021.2 is when the crypto module related stuff becomes good enough to implement basic authentication
if you are doing it before, you need to do the base64 encoding of the username and password first, store that in the secret, and then you can use that to implement basic authentication
m
oooh hmm, okay, maybe the issue is that i did that in reverse. I have the UTF-8 client:password stored, and I'm using secureString.convertEncoding() to get it to Base_64. Lemme try your way instead
b
the problem is that the crypto stuff assumes one encoding
which means you cant do a header like `Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==``
m
hmm. it's like creating a secure string from a Secret just doesn't work. I'm sending the result to a mirror server, and it comes back as just "Basic custsecret_hitc_dev_restlet_base64"
b
the
Basic
is utf-8 while the
QWxhZGRpbjpvcGVuIHNlc2FtZQ==
is base 64
what does your code look like
m
Copy code
const basic  = https.createSecureString({ input: 'Basic ' });
const cred64 = https.createSecureString({ input: 'custsecret_hitc_dev_restlet_base64' });
const auth   = basic.appendSecureString({ secureString: cred64 }); // This isn't working :(
b
{custsecret_hitc_dev_restlet_base64}
m
i'll try putting the whole "Basic MGFmO...." string into one Secret
oooh, really?
b
Copy code
The string to convert to a https.SecureString.

The following patterns are accepted:

    \{[a-fA-F0-9]{32}\} or alternatively { + <32 hexadecimal characters forming a UUID/GUID> + }

    \{custsecret[a-zA-Z0-9_]{1,89}\} or alternatively { + custsecret + <1 up to 89 alfanumeric characters or underscores > + }

    specific payment-plugin tokens
m
apparently i need to improve my RegEx understanding lol. i thought that was just syntax
b
\{ means a literal {
the backslash is the escape
m
i think that is the missing piece for me, thank you so much 🙂
b
you also only need 1 securestring
{custsecret_hitc_dev_restlet_base64} acts as a template expression
so you can just do
Basic {custsecret_hitc_dev_restlet_base64}
m
oooh nice, i'll try that