Roc127
09/01/2023, 2:36 PMAfter you obtain the client ID and private key from the API Console, your application needs to complete the following steps:
1. Create a JSON Web Token (JWT, pronounced, “jot”) which includes a header, a claim set, and a signature.
2. Request an access token from the Google OAuth 2.0 Authorization Server.
3. Handle the JSON response that the Authorization Server returns.NetSuite has the following code sample, but I am struggling to make it work:
NetSuite Applications Suite - Create a JWT Token Using a Secure String - https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/article_0111025224.html#Create-a-JWT-Token-Using-a-Secure-StringLooking into this Slack archive, I have found the following related thread, but with no clear solution:
https://archive.netsuiteprofessionals.com/t/8395506/any-help-directions-to-try-and-test-will-be-really-nice-stuc#a894a393-c1bc-4c67-af44-54c85f5879d1
https://archive.netsuiteprofessionals.com/t/222932/hi-all-i-m-trying-to-connect-to-google-service-using-suitesc#1bb62732-a931-4241-a0e5-7f50a07aaf08
https://archive.netsuiteprofessionals.com/t/14154341/would-the-n-crypto-and-n-crpyto-certificate-be-able-to-perfo#3b5d19c2-1b1e-4[…]8ed-4139261f3944Is it possible to achieve this in an NS scheduled script? Any code examples on how to do this? Thanks in advance!
Clay Roper
09/01/2023, 2:47 PMShawn Talbert
09/01/2023, 3:41 PMbattk
09/01/2023, 7:26 PM`${base64header}.${base64payload}.${signature}`
you dont use any secure string related functionality, so just return a string
this will require you to use crypto.Hmac instead, but its easier to debugbattk
09/01/2023, 7:27 PMRoc127
09/02/2023, 12:07 AM{
"type": "service_account",
"project_id": "...",
"private_key_id": "....",
"private_key": "-----BEGIN PRIVATE KEY-----\...redacted...\n-----END PRIVATE KEY-----\n",
"client_email": "....<http://iam.gserviceaccount.com|iam.gserviceaccount.com>",
"client_id": ".....",
"auth_uri": "<https://accounts.google.com/o/oauth2/auth>",
"token_uri": "<https://oauth2.googleapis.com/token>",
"auth_provider_x509_cert_url": "<https://www.googleapis.com/oauth2/v1/certs>",
"client_x509_cert_url": ".....",
"universe_domain": "<http://googleapis.com|googleapis.com>"
}
So, with how I made it work in Postman (links to explanations in previous message) is using RS256.
The example provided by NetSuite uses HS256, same as the example provided by @Shawn Talbert (thanks again!).
Just for reference, here is an explanation about the differences - RS256 vs HS256 JWT signing algorithms - Auth0 Community - https://community.auth0.com/t/rs256-vs-hs256-jwt-signing-algorithms/58609
But basically, RS256 is an asymmetric algorithm, meaning it uses a public and private key pair, which is what I have in my case.
So, if I understand this part correctly, then I guess what I should be using for my case is some of the methods describe in _N/crypto/certificate Module - https://docs.oracle.com/en/cloud/saas/netsuite/ns-online-help/section_1543432423.html#N%2Fcrypto%2Fcertificate-Module_
Is it therefore possible to generated a valid JWT signature using any of those methods?
I have seen this similar case which seems to follow the same route, but I am still trying to make it work - javascript - Creating JWT Using SuiteScript 2.x for DocuSign API Integration - Stack Overflow - https://stackoverflow.com/questions/68597628/creating-jwt-using-suitescript-2-x-for-docusign-api-integrationClay Roper
09/02/2023, 12:26 AMnsRequire
Clay Roper
09/02/2023, 12:31 AM.pem
file which I uploaded to Netsuite as a certificate. I load that certificate via certId
in the snippet above.
I generated the certificate locally via
$ openssl req -x509 -nodes -newkey rsa:4096 -days 730 -keyout ./prefix_private.pem -out ./prefix_public.pem
Hopefully there's something of use here for you!Roc127
09/05/2023, 4:00 PM