OAuth 2.0 Authentication with SuiteCloud CLI for Node.js(M2M)

 

Introduction: 

In the ever-evolving world of NetSuite development, ensuring secure authentication for your integrations is crucial. SuiteCloud CLI for Node.js provides developers with robust tools to streamline customizations, and with the introduction of OAuth 2.0 authentication, managing these integrations securely has become easier. In this post, we’ll explore how to set up and use OAuth 2.0 authentication for SuiteCloud CLI, including machine-to-machine (M2M) authentication for CI environments.

 

Prerequisites:

To follow along with this guide, you need the following software installed:

- Node.js version 20 LTS 

- Oracle JDK version 17


For a full list of prerequisites, refer to the SuiteCloud CLI for Node.js Installation Prerequisites.

 

Supported Versions:

Ensure you are using the latest version of SuiteCloud CLI available in NPM. Here’s a quick reference:

| Version in NPM | NetSuite Version |

|----------------        |------------------|

| 2.0.0                    | 2024.2           |

| 1.9.X                    | 2024.1           |

 

Installation:

To install the SuiteCloud CLI for Node.js globally, run the following command:

   npm install -g @oracle/suitecloud-cli

For CI environments where you need to automate the installation, bypass the license prompt using:

  npm install -g --acceptSuiteCloudSDKLicense @oracle/suitecloud-cli

Once installed, you can access CLI commands from any directory by using the suitecloud command.

 

Initial Authentication: 

Note: If this is your first time authenticating, use the browser-based authentication first by running suitecloud account: setup. This ensures that the integration record is installed in your account.

 

Authentication for SuiteCloud SDK: 

SuiteCloud CLI authentication, providing two primary options:

 

1. Browser-based Authentication:

If you're not setting up M2M and prefer to authenticate via browser, use the following command:

suitecloud account: setup

This opens a browser window where you can authenticate your role. For future logins, reauthorization is required only when your session expires.

 

2. Machine-to-Machine (M2M) Authentication:

Designed for continuous integration (CI) environments, this option uses digital certificates for authentication, eliminating the need for manual intervention after setup. The following sections will guide you through configuring M2M authentication.

 

 Step-by-Step Guide: Setting up OAuth 2.0 M2M Authentication:

 Step 1: Generate RSA Certificates:

To use machine-to-machine authentication, you need an RSA certificate. You can generate it using openssl by running the following command:

   openssl req -new -x509 -newkey rsa:4096 -keyout private.pem -sigopt rsa_padding_mode:pss -sha256 -sigopt rsa_pss_saltlen:64 -out public.pem -nodes -days 730
 

This command generates two files: 

- private.pem (Private Key) 

- public.pem (Public Key)

          - will be shown like below 

             
 

Make sure to store these in a secure location as they will be required in the following steps.

 

 Step 2: Upload the Public Key to NetSuite:

Mapping for the Client Credentials Flow:
1. Navigate to Setup > Integration > Manage Authentication > OAuth 2.0 Client Credentials (M2M) Setup.
2. Click Create New.
3. In the popup, select the entity and role for this integration.
4. Choose SuiteCloud IDE & CLI as the application.
5. Upload the public.pem file generated in Step 1.

               


 

6. After saving, NetSuite will generate a certificate ID. Make a note of this, as you will need it in the next step.


 

 

 Step 3: Configure SuiteCloud CLI for M2M Authentication:

With the public key uploaded and the certificate ID obtained, set up the SuiteCloud CLI for M2M authentication using the following command: 

    account:setup:ci [--account myAccountId] [--authid myAuthId] [--certificateid myCertificateId] [--domain myNetsuiteDomainURL] [--privatekeypath myPrivateKeyPath]

 Replace the placeholders:

  • -myAccountId: Your NetSuite account ID.
  • - myAuthId: A unique name to identify the authentication setup.
  • - myCertificateId: The certificate ID generated by NetSuite in Step 2.
  • - myNetsuiteDomainURL: The NetSuite domain URL (e.g., https://system.netsuite.com).
  • - myPrivateKeyPath: The full path to the private key file generated in Step 1 (For example: d:/path/private-key.pem).


Conclusion: 

In this guide, we’ve walked through setting up OAuth 2.0 authentication with SuiteCloud CLI, focusing on M2M authentication, perfect for CI environments. By automating authentication, you ensure smooth, secure integration with your NetSuite account, freeing developers from repeated manual authorization.

 

 

 

 

Comments

Popular posts from this blog

Exploring the LLM Module in SuiteScript 2.1 with a Chatbot Example

Integrating AngularJS with NetSuite Suitelets for Dynamic Web Pages