Securing Outgoing Webhooks in Datacake
Learn how to securely forward device events from Datacake using outgoing webhooks, and validate them in external systems like Node-RED using custom authorization headers.
Last updated
Was this helpful?
Was this helpful?
[
{
"id": "http_in_node",
"type": "http in",
"z": "flow",
"name": "Webhook In",
"url": "/webhook",
"method": "post",
"upload": false,
"swaggerDoc": "",
"x": 160,
"y": 100,
"wires": [["check_auth"]]
},
{
"id": "check_auth",
"type": "function",
"z": "flow",
"name": "Check Authorization",
"func": "// Expected token\nconst expectedToken = \"Bearer ABC123\";\n\n// Normalize headers to lowercase (as received)\nconst authHeader = msg.req.headers['authorization'];\n\nif (!authHeader || authHeader !== expectedToken) {\n msg.statusCode = 401;\n msg.payload = { error: \"Unauthorized\" };\n return [null, msg];\n} else {\n return [msg, null];\n}",
"outputs": 2,
"noerr": 0,
"x": 360,
"y": 100,
"wires": [["success_response"], ["unauthorized_response"]]
},
{
"id": "success_response",
"type": "http response",
"z": "flow",
"name": "HTTP 200 OK",
"statusCode": "",
"headers": {},
"x": 580,
"y": 80,
"wires": []
},
{
"id": "unauthorized_response",
"type": "http response",
"z": "flow",
"name": "HTTP 401 Unauthorized",
"statusCode": "",
"headers": {},
"x": 600,
"y": 120,
"wires": []
}
]