HMAC Authentication
Every request to TNS Gateway API is to be authenticated by HMAC by creating a signature of the request payload using API Key and Secret provided by TNS.
How to generate hmac
APIKey(Provided by TNS)Secret(Provided by TNS)- Take the
timestampat the time of signing - Get data/
payload(which will be sent as request body) as string - Concatenate
APIKeyĀā:āĀtimestampĀā:āĀpayload - Generate HMAC by using
Secretprovided by TNS
HMAC should be generated by using SHA512 algorithm.
Here's a simple example of HMAC calculation using JavaScript:
To use CryptoJS.HmacSHA512, you need to ensure that you have the necessary prerequisites set up, including the proper installation and importation of the crypto-js library. Include the CryptoJS library in your HTML file: Add the followingĀ Ā tag to your HTML file to load CryptoJS from a CDN.
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.2.0/crypto-js.min.js"></script>
function generateHMAC(apiKey, secret, requestBody)
{
var time = new Date().getTime();
var rawSignature = apiKey + ":" + time + ":" + requestBody;
var signature = signHMAC(rawSignature, secret);
return signature;
}
function signHMAC(rawSignature, secret) {
const signature = CryptoJS.HmacSHA512(rawSignature, secret);
const hexSignature = CryptoJS.enc.Hex.stringify(signature);
return hexSignature;
}
After generating the HMAC hash, the following headers need to be included in the REST API Request.
Field | Description | Required | Example Value |
apikey | The API Key provided by TNS. | Yes | ba81c80ad011cd918b946f7e957b1b70cc25f14405d1e7801e892e1561295493 |
timestamp | The time stamp taken at the time of signing. | Yes | 1715322040 |
hmac | Generated HMAC Hash value. | Yes | e24e1bfe76b1c846c10c3079ea47202913ad04d66a1434b26470010427dda2d9 |
User-Agent | Identifies the client application making the request. Must include the application name and version (for example, | Yes | MyPOS/2.1.0 |
Important: The User-Agent header is mandatory for all API requests. Requests without a valid User-Agent will be rejected. This header helps TNS identify your integration for support and troubleshooting purposes.
On this page
- HMAC Authentication