Hi All,
I need help as I've been at this for a number of days. I'm trying to setup OAuth2.0 Client Credentials Flow in order to access a NetSuite Restlet from a third party application. I'm using javascript in the third party application. I've been able to manage to get it working in Postman but not from the app. I've setup the integration record specifically for M2M integration using Restlets. I've also created the Client Credentials and setup for my user as well as adding the certificate generated using openssl req -x509 -newkey rsa:4096 -sha256 -keyout auth-key.pem -out auth-cert.pem -nodes -days 730.
Using the kid generated from NetSuite and the private key generated from the openssl command.(Using all of this in Postman works)
My problem is the fetch API - url used: 'https://XXXXXX-sb1.suitetalk.api.netsuite.com/services/rest/auth/oauth2/v1/token'
method: 'POST'
headers: { host: XXXXXX_sb1.suitetalk.api.netsuite.com, content_type: 'application/x-www-form-urlencoded',}
body:{ grant_type : 'client_credentials',
client_assertion_type: 'urn:ietf:params:oauth:client-assertion-type:jwt-bearer',
client_assertion: signedJWT,}
(the signedJWT is a token generated using the jsrsasign node package.
The header for the token consists of:
alg: 'PS256', // Using PS256, which is one of the algorithms NetSuite supports for client credentials
typ: 'JWT',
kid: <key provided by ||Netsuite>,
Payload consists of:
iss: consumerKey, // retrieved from NetSuite
scope: ['restlets', 'rest_webservices'], // scopes specified on integration record
iat: new Date() / 1000, // timestamp in seconds
exp: new Date() / 1000 + 3600, // timestamp in seconds, 1 hour later, which is max for expiration
aud: 'https://XXXXXX-sb1.suitetalk.api.netsuite.com/services/rest/auth/oauth2/v1/token',
The JWT sign consists of 'PS256' json stringified string of the header and payload as well as the certificate private key (generated from openssl command.
The JWT token I tested on jwt.io and it seem correct.
Now I've provided all of the details (except for the key's) but when I try to get the token from the aud I get 503 service unavailable with host value <accountid>_sb1.suitetalk.api.netsuite.com, if I change the '_' to '-' to link my sandbox I get a 400 bad request responce.