Skip to content

Instantly share code, notes, and snippets.

@cafeasp
Created March 10, 2017 12:53
Show Gist options
  • Save cafeasp/aafa69976bc8e9d4769be54aa796c9d5 to your computer and use it in GitHub Desktop.
Save cafeasp/aafa69976bc8e9d4769be54aa796c9d5 to your computer and use it in GitHub Desktop.
Is web hook authentic
public bool IsAuthenticWebhook(NameValueCollection requestHeaders, string requestBody, string shopifySecretKey)
{
string hmacHeader = requestHeaders.Get("X-Shopify-Hmac-SHA256");
if (string.IsNullOrEmpty(hmacHeader))
{
return false;
}
HMACSHA256 hmac = new HMACSHA256(Encoding.UTF8.GetBytes(shopifySecretKey));
string hash = Convert.ToBase64String(hmac.ComputeHash(Encoding.UTF8.GetBytes(requestBody)));
return hash == hmacHeader;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment