Skip to content

Instantly share code, notes, and snippets.

@PamornT
Last active May 31, 2022 08:58
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 PamornT/cef457ecf8c5f188777deefa60438ead to your computer and use it in GitHub Desktop.
Save PamornT/cef457ecf8c5f188777deefa60438ead to your computer and use it in GitHub Desktop.
exports.LINEwebhook = functions.region(region).https.onRequest(async(request, response) => {
console.log('🚀 Start Webhook!!', request.body )
// Verify Signature
const verify = await verify_signature(request, response)
if(!verify) {
response.status(200).send('Unauthorized')
return
}
// Verify Events request must array
// Handle events
response.status(200).send("success")
return
});
const verify_signature = (req, res) => {
const crypto = require('crypto')
const text = JSON.stringify(req.body)
const signature = crypto.createHmac('SHA256', channelSecret).update(text).digest('base64').toString()
if (signature !== req.headers['x-line-signature']) {
console.log('🧨Attack!!', text)
return false
} else {
return true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment