When location updates are sent to your webhook, the data payload will have the following structure:
Navigate to the Webhook Configuration section in your dashboard.
Click on View Secret Key (masked by default).
Securely store this key on your server.
We use HMAC with SHA256 to sign each request.
Signature Algorithm: HMAC-SHA256
String to Sign: The JSON payload as a string
Secret Key: Your shared secret key
To verify incoming requests:
Extract the signature from the X-Weguard-Signature header.
Compute the HMAC signature using the payload and your shared secret key.
Compare the computed signature with the received signature:
If they match, the request is authentic.
If not, reject the request.
Here’s an example of verifying the signature in Go:
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"io/ioutil"
"net/http"
)
key := []byte("your-shared-secret-key")
sig := r.Header.Get("X-Weguard-Signature")
body, _ := ioutil.ReadAll(r.Body)
mac := hmac.New(sha256.New, key)
mac.Write(body)
expectedSig := hex.EncodeToString(mac.Sum(nil))
if hmac.Equal([]byte(sig), []byte(expectedSig)) {
// Signature is valid
w.WriteHeader(http.StatusOK)
} else {
// Signature is invalid
w.WriteHeader(http.StatusUnauthorized)
}
}
http.HandleFunc("/", verify)
http.ListenAndServe(":8080", nil)
}
Each webhook request includes the following custom headers:
X-Webhook-Source: Weguard
X-Weguard-Signature: The HMAC signature for verification.
To ensure reliable data delivery, the webhook employs a retry mechanism:
Automatic Retries: If the endpoint is unreachable or returns an error, retries will be attempted.
Retry Limit: Up to 3 retries.
Exponential Backoff: Delays between retries increase to avoid overwhelming your server.
Failure Handling: After exhausting retries, data will be moved to a dead-letter queue and eventually discarded.
The frequency of location updates depends on:
The number of devices in your account.
The update frequency of each device.
We hope this article was useful. Thank you for reading.
For more WeGuard insights, please explore the Visual Knowledge-base Series
For more details, please visit https://www.weguard.com
If you need any help on this, do call up WeGuard Support at +1(737) 931-1410 Ext. 102 or contact WeGuard Support Email or Initiate Chat