ArtK
ArtK

Reputation: 1179

Integrating NetSuite with AWS Cognito service

I'm integrating NetSuite with custom serverless application running on AWS. The application uses AWS Cognito for authentication. I received NodeJS code from application developer and I was refactoring it to run in NetSuite using SuiteScript 2.1 moduled. I hit a brick wall when I got to HMACs.
I'm trying to implement following line which uses NodeJS crypto package const kDate = crypto.createHmac('sha256', Buffer.from('AWS4' + key, 'utf8')).update(dateStamp).digest();


SuiteScript code looks like this:
let _sKey = https.createSecretKey({
                    encoding: https.Encoding.UTF_8,
                    secret: ('AWS4' + key)
                });                    
                let _kDate = crypto.createHmac({
                    algorithm: crypto.HashAlg.SHA256,
                    key: _sKey
                });                    
                _kDate.update({
                    input: dateStamp
                });                    
                const kDate = _kDate.digest({outputEncoding: encode.Encoding.UTF_8});

                

Explaination SuiteScript crypto.createHmac() inside N/crypto requires crypto.SecretKey object as parameter. SuiteScript crypto.createSecretKey() method only accepts reference to credential-holding UI element or its guid and does not accept string. I found https.createSecretKey() method inside N/https module which accepts sting. This allowed me to create HMAC, update it but when I call digest() method, I get following error: "name":"AN_ERROR_OCCURRED_WHILE_DECRYPT_PASSWORDGUID","message":"An error occurred while decrypting a credential."
This would indicate that credential-holding UI element is still at play and although HMAC created, I still can't perform hashing.
Does anyone have any experience with this type of implementation?
Alternatively, have you performed M2M authentication between NetSuite and AWS using Cognito and M2M authentication or do you know a good case study you can refer me to?

Upvotes: 0

Views: 14

Answers (0)

Related Questions