Callbacks use their own version of authentication
Telesign sends callbacks with headers that can be used for Digest authentication. Just as you must digitally sign all your requests to Telesign when using Digest authentication, Telesign signs all of its requests to your Transaction Callback Service. The details of the signature are slightly different however from those used when sending a request to Telesign.
How to authenticate callbacks
To authenticate the callback, follow these steps:
- Make your Customer ID and API Key accessible to your integration code. For help finding these items, see the support article How do I find my Customer ID and API Key?.
- Example Customer ID:
- Example API Key:
- Save the value of one of two headers from the request from Telesign (both are always included):
Convert the body of the request to a string (decode using UTF-8 for a JSON payload) and save it to use in a later step. This is your string-to-sign.
Unlike when you make a request to Telesign, this signature only includes the body of the message.
Encode your string-to-sign using UTF-8 encoding.
Base-64 decode your API Key.
Save the hashing method ("auth_method") you are using to authenticate. Currently only "HMAC-SHA256" is supported. It can be either upper-cased or lower-cased.
Create a new HMAC object using your decoded API Key, your string-to-sign, and the same "auth_method" string you saved earlier. Here's an example of how you might do that in Python:
hmac_obj = hmac.new(decoded_api_key, encoded_string_to_sign, digestmod=auth_method)
Create a digest from this HMAC object.
Decode this digest with UTF-8 encoding.
Based-64 encode the decoded digest. This is your expected signature.
Parse the signature from the
x-ts-authorizationheader value you saved earlier. The header value has the format "TSA" + a space + Customer ID + ":" + signature. Split the value into two parts using the space (" ") character. Save the second part.
Split that string again using the ":" character. Save the second part. This is the signature.
Compare the signature to the expected signature. Here is an example of how to do that using Python:
Feel free to copy this code for authenticating requests from Telesign and adapt it to your integration:
Updated 8 days ago