じまろぐ

めめ

LINE Messaging API webhookの署名検証 on Lambda

const crypto = require('crypto');
const channelSecret = 'xxxxxxx' // envとかから取る

exports.handler = async(event) => {
    const body = Buffer.from(event.body, 'base64').toString()
    const signature = crypto.createHmac('SHA256', channelSecret).update(body).digest('base64');
    const isSignatureMatched = signature === event.headers['X-Line-Signature'];
    console.log('signature matched:', isSignatureMatched); // LINEからのリクエストならtrueになる
}