Token Based Authentication is widely used in NetSuite Integrations such as RESTlets, SOAP Web Services, and SuiteAnalytics Connect. As part of the TBA Authorization Flow, the Timestamp, Signature, and Nonce must be supplied to generate the signature.
The sample code below must be ran using PowerShell:
$nonce=''
$set="anyrandomcharactercombinationhere123".ToCharArray()
for($x=0;$x-lt20;$x++){
$nonce+=$set|Get-Random
}
$account='xxxxxxx'#NetSuite Account ID
#Consumer Key and Secret from the Integration Record, Token and Token Secret from the User’s Access Tokens
$consumer_Key='xxxxx'
$consumer_secret='xxxxx'
$token='xxxxxxx'
$token_secret='xxxxxxx'
$timestamp=[int][double]::Parse((Get-Date(get-date).touniversaltime()-UFormat%s))
$timestamp=[string]$timestamp
$msg=$account+'&'+$consumer_Key+'&'+$token+'&'+$nonce+'&'+$timestamp
$secret=$consumer_secret+'&'+$token_secret
$hmacsha=New-ObjectSystem.Security.Cryptography.HMACSHA256
$hmacsha.key=[Text.Encoding]::ASCII.GetBytes($secret)
$signature=$hmacsha.ComputeHash([Text.Encoding]::ASCII.GetBytes($msg))
$signature=[Convert]::ToBase64String($signature)
echo$timestamp
echo$signature
echo$nonce
The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Oracle + NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.
Oracle + NetSuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Oracle + NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.
Oracle + NetSuite Inc. shall not be liable for any direct, indirect, or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.
—
Have you got any feedback? Let us know in the comments!