Hi All,
I'm new to this OAuth 2.0 Client Credential Grant flow. I'm having problem correctly using jsrsasign.js, or I'm unable to spot my scripting mistakes. SuiteScript Debugger reported error "init failed:Error: not supported argument" upon signing the JWT in my require() script in debugger. jsrsasign.js of course has no problem, the problem must be how I am using it. Please can anyone show me the way?
jsrassign.js was copy/paste into my require() script for debugging, and it was downloaded from
I've referenced SuiteAnswer 1013484 for using Postman to get Access Token from OAuth 2.0 Client Credential; and got it working. ie. Postman returned the Access Token, see it using jsrsasign without problem, and created OAuth 2.0 Authorized Application record at OAuth 2.0 Netsuite instance.
The error "init failed:Error: not supported argument" happens at line using jsrsasign: KJUR.jws.JWS.sign()
The context of the script is as follows:
const accountID = 'xx123456; //OAuth 2.0 Netsuite instance, with a RESTlet.
const href = `https://${accountID}.suitetalk.api.netsuite.com/services/rest/auth/oauth2/v1/token`;
const consumerKey = 'ckckckckck; //from integration record
const privateKey = 'pkpkpkpkpk'; //from private key of certificate.pem stored at OAuth 2.0 Client Credential
const kid = 'kidkidkidkid; //Certificate ID from OAuth 2.0 Client Credential
const algorithm = 'PS256';
JWT header and payload, each are JSON stringified:
const jwtHeader = {kid, alg:algorithm, typ:'JWT'};
const jwtPayload = {aud:href, iss:consumerKey, scope:['restlets'], iat: (new Date()/1000), exp: (new Date()/1000)+3600};
JWT is signed as follows:
const encodedPrivateKey = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(privateKey));
const signedJWT = KJUR.jws.JWS.sign(algorithm, stringifiedJwtHeader, stringifiedJwtPayload, privateKey);
certificate.pem was created at console with command and merged from auth-key.pem to auth-cert.pem to a new file certificate.pem:
openssl req -x509 -newkey rsa:4096 -sha256 -keyout auth-key.pem -out auth-cert.pem -nodes -days 730
privateKey was the very long text string (without line breaks) from auth-key.pem
I tried carefully review above against various SuiteAnswers and unable to spot deviations and jsrsasign.js can't be the problem. I am exhausted on where to look for my problem. Please drop me hints. Thank you.
Regards, Frankey.