API Signature & Webhook Validation
Wish you safe and sound...
To ensure the authenticity and integrity of your message, all API request must be signed securely by adding X-Fp-Signature
in request header. Similarly, the partners' backend system should validate X-Fp-Signature
in request header of the webhook notification sent by FaTPay as well.
Signature for API request
As Premium Partner, you will generate APIPrivateKey
during [Onboarding] process, which is essential to the signature producing.
Do not share the private key to anyone or public repositories. Your account might be blocked once the credential leakage is detected. FaTPay reserves the right to take any other actions and pursue any other legal rights available to us.
Procedure
Please follow this guide to generate the signature, which uses RSA-SHA256
algorithm.
Retrieve parameters
Firstly, retrieve all the common header parameters except
X-Fp-Signature
. Convert all the keys to lowercase and build a map with all key-value pairs;Secondly, retrieve all query parameters and add to the map;
Thirdly, remove all the items with null keys or null values;
Sort parameters
Sort all parameter keys in ascending order(as per ASCII values of the characters);
Prepare
to-be-signed-payload
Firstly convert the sorted map to a string
request-key-value-parameters-string
in the form ofkey=value
and concatenate them with&
character as the separator;Then concatenate the final string by the following rule. Please exclude
http
/https
inrequest-domain
. Andrequest-method
should be all uppercase asGET
/POST
;request-method
+request-domain
+request-URI
+?
+request-key-value-parameters-string
Now we get a string called
to-be-signed-payload
;
Compute signature
Next use
APIPrivateKey
to generate signature for the stringto-be-signed-payload
from last step viaRSA-SHA256
algorithm. Please check [API Signature Demo];
Assign signature
Finally, assign the signature to
X-Fp-Signature
in the request header, and call FaTPay APIs. Once it's received by FaTPay gateway, it will be validated withAPIPublicKey
. If it is passed, the data will be responded accordingly;
Example
Let's take a virtual API as testSignature
with GET
method to go through the whole procedure step by step. The URI of this API is api/testsignature
.
Retrieve parameters
Firstly, retrieve all the common header parameters except X-Fp-Signature
. Convert all the keys to lowercase and build a map with all key-value pairs.
Secondly, retrieve all query parameters and add to the map.
Thirdly, remove all the items with null keys or null values. Now we get
Sort parameters
Sort all parameter keys in ascending order(as per ASCII values of the characters);
Prepare to-be-signed-payload
Firstly convert the sorted map to a string request-key-value-parameters-string
in the form of key=value
and concatenate them with &
character as the separator. We get
Then concatenate the final string by the rule:
request-method
+request-domain
+request-URI
+?
+request-key-value-parameters-string
Now to-be-signed-payload
turns out to be:
Compute signature
Next use APIPrivateKey
to generate signature for the string to-be-signed-payload
from last step via RSA-SHA256
algorithm. The signature:
akZjLiZak0v07CzJoKr7/uKgsAzW2a8DXevy98xg3k6HeOtiU2OyWeEYuQtX/G5EuOs5NeagnIwsIxxiFCQoo6hh2OkgxuEphUQNg1B2HO9cYxpJWRKJfxcf20fJ/OIKFfI75PLMqSGRSmx5tVl+9vP4mBzQwpFtgYok2nrWZU4=
Assign signature
Finally, assign the signature to X-Fp-Signature
in the request header, and call FaTPay APIs.
Webhook validation
For security reason, we highly recommend the backend system of our partners to validate the signature of webhook whenever receiving a notification of order status change.
FaTPay will inform the partners about the order status changing by calling the predefined webhook endpoints. The partners' backend system should validate X-Fp-Signature
in request header to check the authenticity and integrity of such webhook message. Use WebhookPublicKey
to verify that FaTPay generated a webhook request and that it didn’t come from a server acting like FaTPay.
FaTPay generates signatures usingRSA-SHA256
algorithm. The validation procedure is quite similar to the signature generating procedure.
Retrieve parameters
Firstly, extract all the parameters starting with
X-Fp
exceptX-Fp-Signature
from header. Convert all the keys to lowercase and build a map with all key-value pairs. Check header details;Secondly, retrieve all query parameters and add to the map;
Thirdly, remove all items with null keys or null values;
Sort parameters
Sort all parameter keys in ascending order(as per ASCII values of the characters);
Prepare
to-be-verified-payload
Firstly convert the sorted map to a string in the form of
key=value
and concatenate them with&
character as the separator;Then concatenate the final string by the rule:
request method
+request domain
+request URI
+?
+<request key-value parameters string>
. Please remember to excludehttp://
orhttps://
inrequest domain
;Now you will get a string called
to-be-verified-payload
;
Validate signature
Finally, extract the
to-be-verified-signature
fromX-Fp-Signature
in the webhook header. Validate the signature(RSA-SHA256
algorithm) with the stringto-be-verified-payload
from last step andWebhookPublicKey
provided by FaTPay during [Onboarding] process;
Last updated