Testing and Security
Related Articles
This will serve as guide as how you will be able to test the webhook integration works with your system. You should be able to just invoke the endpoint mentioned below, supplied with the API-key in the header.
Target Endpoint:
POST https://api.begini.co/v1/webhooks-management/test
Headers:
Api-key: <API Key from Integration>
Response Status
Status Code | Response Body | Description |
200 |
|
This will identify that the webhook was successfully transmitted to the webhook receiver. |
400 |
|
Api-key is not SUPPLIED in the request header |
403 |
|
Api-key is NOT valid or is not registered in the system. Please create an API-key in the begini dashboard in order to use the Test API for webhooks. |
424 |
|
Webhook is not set in the Dashboard |
422 |
|
This means that the webhook was able to communicate to the webhook receiver, but the webhook receiver returned an error. |
503 |
|
This means that Begini Webhook System cannot connect to the Client's Webhook Receiver |
Security Features
- Begini advises to whitelist the IPs of the Begini Platform for additional security.
- Begini uses HMAC signature (Hexdigest) to ensure that the webhook transmitted is not altered in the middle and the authenticity of the payload really comes from the Begini Platform. In order to verify the HMAC signature, the API Key will be used to generate the HMAC Hex Digest that will be compared to the signature. Please sample code how to validate the HMAC
Python using FastAPI:
import hashlib
import hmac
from fastapi import APIRouter, Request, HTTPException, status
test_router = APIRouter()
@test_router.post('/webhook-receiver')
async def test(request: Request):
payload = await request.body()
signature_from_request = request.headers.get("X-Signature")
expected_signature = hmac.new('<API-Key>'.encode('utf-8'), payload, digestmod=hashlib.sha512).hexdigest()
if not hmac.compare_digest(expected_signature, signature_from_request):
raise HTTPException(status_code=403, detail='Validation Failure')
return status.HTTP_200_OK