Skip to content

Instantly share code, notes, and snippets.

@wzul
Forked from constantm/itr.js
Created January 6, 2023 03:40
Show Gist options
  • Save wzul/bef65257e4f9142298cda7d0f1d5fb00 to your computer and use it in GitHub Desktop.
Save wzul/bef65257e4f9142298cda7d0f1d5fb00 to your computer and use it in GitHub Desktop.
NodeJS implementation in Pipedream of "Intent to Receive" for Xero webhooks
async (event, steps) => {
// NodeJS implementation in Pipedream of "Intent to Receive" for Xero webhooks
const { createHmac } = await import('crypto');
const xero_webhook_key = 'OSd0eLlVIY9ZhViEqlDUh4+6n6M+Lo+eDaEJheJ6OCCgWwIz2D3JIAU6jPMipHRbgKTLz2uJ+xiACXGDBLrgdA==' // Get this from the Xero app
const body_string = Buffer.from(steps.trigger.raw_event.body_b64, 'base64').toString() // Use RAW body data so that Pipedream doesn't break our data
const xero_hash = steps.trigger.event.headers["x-xero-signature"] // Could probably shorten, but keeping it long for consistency
let our_hash = createHmac('sha256', xero_webhook_key).update(body_string).digest("base64") // Generate the hash Xero wants
let statusCode = xero_hash == our_hash ? 200 : 401 // If the hashes match, send a 200, else send a 401
return $respond({
status: statusCode
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment