Protect API requests by generating a signature that verifies request authenticity
signature is an encrypted hash value used to verify the authenticity and integrity of API requests sent to the SingleView platform. It ensures that the request data originates from a trusted client and that the payload has not been altered during transmission.
Before making certain API calls, the client must generate a signature using the request body and a shared Signature Key provided during onboarding. The generated signature is then included in the API request so that the system can validate the request.
When the platform receives a request, it recalculates the signature using the same method and compares it with the signature provided by the client. If both signatures match, the request is considered valid and processed. If they do not match, the request is rejected.
Requests with an invalid or missing signature will return an Unauthorized or Invalid request response.
The following example request body is used to demonstrate the signature generation process:
{
"clientId": "abcd",
"clientCode": "xyz",
"merchantId": "merchant",
"grantType": "client_credentials"
}
Below are sample implementations for generating a signature in different programming languages:
const crypto = require("crypto");
const SIGNATURE_KEY = "1234567890"; // your shared key
function generateSignature(reqBody) {
const jsonString = JSON.stringify(reqBody);
const base64Data = Buffer.from(jsonString, "utf-8").toString("base64");
const dataToHash = base64Data + SIGNATURE_KEY;
const signature = crypto.createHash("sha256").update(dataToHash).digest("hex");
return signature;
}
const body = {
clientId: "abcd",
clientCode: "xyz",
merchantId: "merchant",
grantType: "client_credentials"
};
console.log("Generated Signature:", generateSignature(body));