Headless Machines
Using OAuth on a Headless Machine
To create NetSuite data sources on headless servers or other machines on which the driver cannot open a browser, you need to authenticate from another machine. Authentication is a two-step process.
- Instead of installing the driver on another machine, you can follow the steps below to obtain the OAuthVerifier value. Or, you can install the driver on another machine and transfer the OAuth authentication values, after you authenticate through the usual browser-based flow.
- You can then configure the driver to automatically refresh the access token from the headless machine.
Using the Credentials for a Custom OAuth App
Create a Custom OAuth App
Creating a custom OAuth app is optional in the headless OAuth flow; you can skip creating an app by connecting with the driver's embedded OAuth credentials (only for Schema = SuiteQL). You might want to create a custom OAuth app to change the information displayed when users log into NetSuite to grant permissions to the driver.
See Creating a Custom OAuth App for a procedure. You can then follow the procedures below to authenticate and connect to data.
Obtain a Verifier Code
Set the following properties on the headless machine:
- AccountId: Set this to the account id you are connecting to.
- InitiateOAuth: Set this to OFF.
- OAuthClientId: Set this to the Consumer Key assigned when you specified your app.
- OAuthClientSecret: Set this to the Consumer Secret assigned when you specified your app.
- Scope: Set this value to match what your app has access to when using OAuth 2.0. Set it to restlets, rest_webservices, or restlets rest_webservices.
You can then follow the steps below to authenticate from another machine and obtain the OAuthVerifier connection property.
- Call the GetOAuthAuthorizationURL stored procedure with the CallbackURL input parameter set to the exact Redirect URI you specified in your app settings.
- When using OAuthVersion 1.0 or Schema set to SuiteTalk, the procedure will additionally return an AuthToken and AuthKey. Save these values - they will need in the next step.
- Open the returned URL in a browser. Log in and grant permissions to the driver. You are then redirected to the callback URL, which contains the verifier code.
- Save the value of the verifier code. You will set this in the OAuthVerifier connection property.
On the headless machine, set the following connection properties to obtain the OAuth authentication values:
- AccountId: Set this to the account id you are connecting to.
- OAuthClientId: Set this to the Consumer Key assigned when you specified your app.
- OAuthClientSecret: Set this to the Consumer Secret assigned when you specified your app.
- Scope: Set this value to match what your app has access to when using OAuth 2.0. Set it to restlets, rest_webservices, or restlets rest_webservices.
- OAuthVerifier: Set this to the verifier code.
- AuthToken: Set this to the AuthToken if OAuthVersion is 1.0 or Schema set to SuiteTalk.
- AuthKey: Set this to the AuthKey if OAuthVersion is 1.0 or Schema set to SuiteTalk.
- OAuthSettingsLocation: Set this to persist the encrypted OAuth authentication values to the specified file.
- InitiateOAuth: Set this to REFRESH.
After the OAuth settings file is generated, set the following properties to connect to data:
- AccountId: Set this to the account id you are connecting to.
- OAuthClientId: Set this to the Integrator Key assigned when you specified your app.
- OAuthClientSecret: Set this to the Secret Key assigned when you specified your app.
- OAuthSettingsLocation: Set this to the file containing the encrypted OAuth authentication values. Make sure this file gives read and write permissions to the provider to enable the automatic refreshing of the access token.
- InitiateOAuth: Set this to REFRESH.
Transfer OAuth Settings
Follow the steps below to install the driver on another machine, authenticate, and then transfer the resulting OAuth values.
On a second machine, install the driver and connect with the following properties set:
- AccountId: Set this to the account id you are connecting to.
- OAuthSettingsLocation: Set this to a writable text file.
- InitiateOAuth: Set this to GETANDREFRESH.
- OAuthClientId: Set this to the Consumer assigned when you specified your app.
- OAuthClientSecret: Set this to the Consumer Secret assigned when you specified your app.
- CallbackURL: Set this to the Redirect URI you specified in your app settings.
Test the connection to authenticate. The resulting authentication values are written, encrypted, to the path specified by OAuthSettingsLocation. Once you have successfully tested the connection, copy the OAuth settings file to your headless machine. On the headless machine, set the following connection properties to connect to data:
- AccountId: Set this to the account id you are connecting to.
- InitiateOAuth: Set this to REFRESH.
- OAuthClientId: Set this to the Consumer Key assigned when you specified your app.
- OAuthClientSecret: Set this to the Consumer Secret assigned when you specified your app.
- OAuthSettingsLocation: Set this to the path to your OAuth settings file. Make sure this file gives read and write permissions to the driver to enable the automatic refreshing of the access token.