This commit is contained in:
Jay
2018-06-25 18:07:10 +08:00
commit 075b68012e
9 changed files with 120 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
const config = require('../../config')
const crypto = require('crypto')
const verifyLine = async (c, n) => {
if (!('request' in c) || !('raw' in c.request)) return c.throw(400, 'body not found')
let xSignature = c.get('x-line-signature') || ''
if (typeof xSignature !== 'string' || xSignature.length === 0) return c.throw(400, 'signature not found')
let signature = crypto.createHmac('SHA256', config.line.secret).update(c.request.raw).digest('base64')
if (signature !== xSignature) return c.throw(403, 'signature not match')
return n()
}
module.exports = {
verifyLine
}