Last active
May 31, 2022 08:58
-
-
Save PamornT/cef457ecf8c5f188777deefa60438ead to your computer and use it in GitHub Desktop.
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
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