first
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user