To make sure the webhook is sent by Extend Commerce it is signed. It is optional to use the signature for verification.
Body is signed using SHA256 with clientsecret. The signed value is added in header 'ms-signature'
ClientSecret:
Body: the full request body
SignatureFromHeader: request header 'ms-signature'
Sample pseudo code:
byte[] secret = Encoding.UTF8.GetBytes(ClientSecret);
using (var hasher = new HMACSHA256(secret))
{
byte[] data = Body.ToByteArray();
actualHash = hasher.ComputeHash(data);
}
byte[] expectedHash = FromHex(SignatureFromHeader).ToByteArray()
if(IsSecretEqual(expectedHash, actualHash))
{
//process web hook
}
Sample
ClientSecret = secret123
Body = {'test':'test2'}
BodyAsHex = 7B2774657374273A277465737432277D
ms-signature = sha256=25FB6994568A75CD233E04BA1C653AF1BF476041CC543AF04F82CAAC482C201A