Created
October 29, 2021 10:07
-
-
Save joawan/0dfbbde61573496a36026d7b14231d10 to your computer and use it in GitHub Desktop.
Verify Twilio signatures
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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