https://dev.to/appwrite/level-up-your-webhook-security-with-appwrite-015-50mo
I followed the above the tutorial wrote the following code:
var appwriteResponse map[string]any
// TODO: Verify the webhook secret
payloadBody, err := c.GetRawData()
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to read request body"})
return
}
signature, err := generateSignature(string(payloadBody))
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to verify webhook signature"})
return
}
headerSignature := c.GetHeader("X-Appwrite-Webhook-Signature")
if signature != headerSignature {
c.JSON(http.StatusUnauthorized, gin.H{"error": "Failed Authentication Check"})
return
}
func generateSignature(payloadBody string) (string, error) {
data := "https://www.my-hosted-backend.com/appwrite/user/location" + payloadBody
hm := hmac.New(sha1.New, []byte(os.Getenv("APPWRITE_WEBHOOK_SECRET")))
hm.Write([]byte(data))
return base64.StdEncoding.EncodeToString(hm.Sum(nil)), nil
}
Is something wrong with the logic?