package shield
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"time"
)
type ScoreDetail struct {
Value int `json:"Value"`
Description string `json:"Description"`
}
type WebhookData struct {
RequestID string `json:"RequestID"`
SessionID string `json:"SessionID"`
CookieID string `json:"CookieID"`
DeviceID string `json:"DeviceID"`
VisitorID string `json:"VisitorID"`
UserHID string `json:"UserHID"`
IP string `json:"IP"`
OS string `json:"OS"`
Country string `json:"Country"`
Score int `json:"Score"`
Details []ScoreDetail `json:"Details"`
LastRequestTime time.Time `json:"LastRequestTime"`
Phase string `json:"Phase,omitempty"`
}
func VerifyWebhook(data WebhookData, assing, secret string) bool {
b, err := json.Marshal(data)
if err != nil {
return false
}
mac := hmac.New(sha256.New, []byte(secret))
mac.Write(b)
expected := hex.EncodeToString(mac.Sum(nil))
return hmac.Equal([]byte(assing), []byte(expected))
}