Using HMAC Authentication Type
HMAC is a specific type of authentication code involving a cryptographic hash function and a secret key. It may be used to simultaneously verify both the data integrity and the authentication of a message, as with any MAC.
Descope allows you to use HMAC to sign the payload of your HTTP Connector. The outcome signature will be sent in the x-descope-webhook-s256
header.
The recipient service should use this secret to validate the payload's integrity and authenticity by verifying the supplied signature.
Validating the HMAC Signature
To validate the HMAC signature, the code could look something like this:
Or this:
Mocking an HMAC Signature
If you wish to test the HMAC signature validation, you can use the following code to generate a valid signature for a given payload and secret, then include it in the headers. Note that Descope creates the HMAC signature from a JSON string, not the raw post body.