Skip to content

Instantly share code, notes, and snippets.

@jirawatee
Last active Feb 18, 2021
Embed
What would you like to do?
Code sample for verifying signature from LINE webhook
let text = JSON.stringify(req.body)
text = text.replace(/([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g, (e) => {
return "\\u" + e.charCodeAt(0).toString(16).toUpperCase() + "\\u" + e.charCodeAt(1).toString(16).toUpperCase()
})
const signature = crypto.createHmac('SHA256', LINE_CHANNEL_SECRET).update(text).digest('base64').toString()
if (signature !== req.headers['x-line-signature']) {
return res.status(401).send('Unauthorized')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment