Signature Validation
Last updated
Last updated
The lean.x signature authentication adds an additional security layer for API requests by generating a unique signature for each request. This signature ensures the authenticity and integrity of the requests made to the API. Each signature is valid only for 5 minutes within the timestamp and is tied to the specific API key. Merchants have the option to enable or disable this feature based on their security needs.
You may find this feature under API > API Key > Edit API Key > X-Signature. Refer screen shot below as reference.
Message Construction:
When the feature is enabled, the system will automatically authenticate every API request send to the system. The signature will be a concatenation of the following elements in this specific order:
HTTP_METHOD: The HTTP method used for the request (GET, POST, PUT, DELETE, PATCH).
UUID: The unique identifier (UUID) associated with the API key. Can be retrieved from Merchant Portal
URL_PATH: The endpoint path of the API request.
TIME_STAMP: The current Unix timestamp in seconds.
AUTH_TOKEN: The authentication token associated with the API key.Can be retrieved from Merchant Portal
NONCE: A unique random number or string, typically a UUID4, to ensure the request's uniqueness.
HMAC Generation:
Our system will require your application to generate an HMAC (SHA256) signature of the constructed message using the Hash Key as the secret key , which can be retrieved from Merchant Portal. This HMAC output serves as the X-Signature.
Request Header Injection:
The generated X-Signature, along with the timestamp and nonce, is included in the request headers. The headers will include:
x-signature
: The HMAC-SHA256 signature.
x-timestamp
: The Unix timestamp used in the signature.
x-nonce
: The unique nonce used in the signature.
Validation:
On the server-side, the received X-Signature is validated by reconstructing the message and comparing the signature with the one received in the header. If they match, the request is authenticated and processed.
A typical API request header with HMAC signature with additional header will look like this
This process ensures that each API request is securely authenticated and is valid for a short time, reducing the risk of replay attacks. Merchants should enable this feature to enhance the security of their API transactions.
This code snippet collection will help you with HMAC generation from your system