Skip to content

Instantly share code, notes, and snippets.

@joawan
Created October 29, 2021 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joawan/0dfbbde61573496a36026d7b14231d10 to your computer and use it in GitHub Desktop.
Save joawan/0dfbbde61573496a36026d7b14231d10 to your computer and use it in GitHub Desktop.
Verify Twilio signatures
const qs = require('querystring');
const twilio = require('twilio');
module.exports.process = async (event, config) => {
const { 'X-Forwarded-Proto': proto, 'X-Twilio-Signature': sign } = event.headers;
const { path, domainName } = event.requestContext;
const url = `${proto}://${domainName}${path}`;
if (!twilio.validateRequest(config.twilioToken, sign, url, qs.parse(event.body))) {
throw new Error('Invalid signature');
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment