This topic contains 3 replies, has 0 voices, and was last updated by mayerlench 6 years, 6 months ago.
-
AuthorPosts
-
October 2, 2017 at 12:36 pm #18247
charles.wallace.arcserveI am trying to implement a JSON Web Token, and thus trying to get crypto.hmac to work, but I’m having issues with it. I made a password tool from a modified version of the suitelet from this thread, and I have a password guid that I have generated and restricted for use on my custom script id, that I am using in that custom script. However, each time the code gets to the .digest() call, it throws UNEXPECTED_ERROR. I’m still new to SuiteScript and I’m not sure what I am doing wrong:
Code:
var sKey = crypto.createSecretKey({
guid: “6332f5d7575a481388a24b924292d552”, // restrictToDomains=[‘system.sandbox.netsuite.com’], restrictToScriptIds=[]
encoding: encode.Encoding.HEX
});
var hmacSignature = crypto.createHmac({
algorithm: crypto.HashAlg.SHA256,
key: sKey,
});hmacSignature.update({
input: encHeader + “.” + encPayload,
inputEncoding: encode.Encoding.UTF_8
});
var signature = hmacSignature.digest({
outputEncoding: encode.Encoding.BASE_64_URL_SAFE
});
return encHeader + “.” + encPayload + “.” + signature;
Any assistance would be greatly appreciated.Thanks,
Charles
This is a cached copy. Click here to see the original post. -
October 2, 2017 at 11:30 pm #18248
holly2k+1, unable to run the example code at all, hope NS provide working example other than this a UNEXCEPTED_ERROR case
-
October 3, 2017 at 10:23 pm #18249
BrettKnightsDid you get this? You have to use form.addSecretKeyField not addCredentialField
The NS example shows
Code:
form.addCredentialField({
id : ‘username’,
label : ‘Pwd’,
restrictToDomains : [config.host],
restrictToScriptIds : config.targetScript,
restrictToCurrentUser : false
});
but for HMAC it should be:Code:
form.addSecretKeyField({
id : ‘username’,
label : ‘Pwd’,
restrictToScriptIds : config.targetScript,
restrictToCurrentUser : false
});
If you are having problems with interoperability the other thing to watch for is case. Node.js at least produces its hex values lower case but the SS2 Hmac digest gives upper case. So convert before comparing. -
May 7, 2018 at 10:21 am #18250
mayerlenchHaving the same issue right now. Netsuites example code does not work!
-
AuthorPosts
You must be logged in to reply to this topic.