Skip to main content
By the end of this guide you can verify that every webhook event came from Fintoc by checking the Fintoc-Signature header. Fintoc signs every event sent to your webhook endpoints with the Fintoc-Signature header. This header lets you verify that Fintoc, not a third party, sent each event. Fintoc generates a secret when you register a webhook endpoint. This secret is necessary to validate the Fintoc signature of every event.

Verify that Fintoc sent the event

Each event sent by Fintoc includes the Fintoc-Signature header. The header contains a t timestamp and a v1 signature. For example:
Each signature is a hash-based message authentication code (HMAC). Fintoc generates it from the raw request body and the timestamp, using SHA-256 and your webhook endpoint secret.

Validate the signature with the Fintoc SDK

If you use Node or Python, verify webhook signatures with the Fintoc Node SDK or Fintoc Python SDK.
For a complete working example, check the full code here.

Validate the signature with your own code

If you want to write your own implementation or use a different programming language, follow these steps:

Extract the timestamp and the signature

Split the Fintoc-Signature header into an array by the , character. Then, split each element of the generated array by the = character to obtain a key-value pair. Finally, get the corresponding values for each key.

Rebuild the signed message

The signed message is the timestamp, a . character, and the raw body of the request. Rebuild the message with the timestamp you extracted from the Fintoc-Signature header.
Use the raw, unparsed request body directly from the request. Different libraries can represent the parsed JSON differently. For example, message should look like this:

Generate the signature

Now that you have the message to sign, generate the signature using the SHA-256 hash function and the secret generated when creating the webhook endpoint.

Compare the signatures

Compare the signature you extracted from the Fintoc-Signature header with the one you just generated. If both signatures match, the event came from Fintoc.

Prevent a replay attack

To prevent a replay attack, define a tolerance range for how old an event can be. When you receive an event, read the timestamp from the Fintoc-Signature header. Compare the timestamp with the current time. A tolerance of five minutes is a reasonable default. Accept events within five minutes of the current time, and discard older events.

Test the integration

Confirm that signature validation works before you rely on it in production. Trigger a test event for your webhook endpoint from the Fintoc Dashboard, then check how your handler responds:
  • With a valid signature, your handler validates the header and processes the event.
  • With an invalid signature, for example after you change one character in the v1 value or use the wrong secret, your handler rejects the event and returns a 400 status.