Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add validation logic for zoom-meeting-webhook-handler #19

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions functions/zoom-meeting-webhook-handler/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require('dotenv').config();

const crypto = require('crypto');

const { updateMeetingStatus, updateMeetingAttendence } = require('./slack');

const rooms = require('../../data/rooms.json');
Expand All @@ -9,17 +11,24 @@ const EVENT_MEETING_ENDED = 'meeting.ended';
const EVENT_PARTICIPANT_JOINED = 'meeting.participant_joined';
const EVENT_PARTICIPANT_LEFT = 'meeting.participant_left';

const ZOOM_AUTH =
process.env.TEST_ZOOM_WEBHOOK_AUTH || process.env.ZOOM_WEBHOOK_AUTH;
const ZOOM_SECRET =
process.env.TEST_ZOOM_WEBHOOK_SECRET_TOKEN ||
process.env.ZOOM_WEBHOOK_SECRET_TOKEN;

const handler = async function (event, context) {
try {
if (
!(
event.headers.authorization === ZOOM_AUTH ||
event.headers['x-zm-signature'] === ZOOM_AUTH
)
) {
const message = `v0:${
event.headers['x-zm-request-timestamp']
}:${JSON.stringify(event.body)}`;

const hashForVerify = crypto
.createHmac('sha256', ZOOM_WEBHOOK_SECRET_TOKEN)
.update(message)
.digest('hex');

const signature = `v0=${hashForVerify}`;

if (request.headers['x-zm-signature'] !== signature) {
console.log('Unauthorized', event);
return {
statusCode: 401,
Expand All @@ -29,6 +38,22 @@ const handler = async function (event, context) {

const request = JSON.parse(event.body);

console.log(request);

if (request.event == 'endpoint.url_validation') {
const hashForValidate = crypto
.createHmac('sha256', ZOOM_SECRET)
.update(request.payload.plainToken)
.digest('hex');
return {
statusCode: 200,
body: JSON.stringify({
plainToken: request.payload.plainToken,
encryptedToken: hashForValidate,
}),
};
}

// check our meeting ID. The meeting ID never changes, but the uuid is different for each instance

const room = rooms.find(
Expand Down