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

Created appZoom.js file with validation logic for endpoint URL #6

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ build/Release
# Dependency directories
node_modules/
jspm_packages/
.env

# TypeScript v1 declaration files
typings/
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ npm start
```
Alternativelly, you can run one of the following apps:
`npm run startFB`
`npm run startZoom`

The app runs by default on port 3000

Expand Down
64 changes: 64 additions & 0 deletions appZoom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
require('dotenv').config()
const express = require('express')
const bodyParser = require('body-parser')
const crypto = require('crypto')

const app = express()
app.use(bodyParser.json())
const port = 3000

app.post('/*', function (req, res) {
let response;
console.log("Headers:", req.headers);
console.log("Body:", req.body);

// construct the message string
const message = `v0:${req.headers['x-zm-request-timestamp']}:${JSON.stringify(req.body)}`

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

// hash the message string with your Webhook Secret Token and prepend the version semantic
const signature = `v0=${hashForVerify}`

// you validating the request came from Zoom https://marketplace.zoom.us/docs/api-reference/webhook-reference#notification-structure
if (req.headers['x-zm-signature'] === signature) {

// Zoom validating you control the webhook endpoint https://marketplace.zoom.us/docs/api-reference/webhook-reference#validate-webhook-endpoint
if(req.body.event === 'endpoint.url_validation') {
const hashForValidate = crypto.createHmac('sha256', process.env.ZOOM_WEBHOOK_SECRET_TOKEN).update(req.body.payload.plainToken).digest('hex')

response = {
message: {
plainToken: req.body.payload.plainToken,
encryptedToken: hashForValidate
},
status: 200
}
console.log("Response:", response.message)

res.status(response.status)
res.json(response.message)
} else {
response = {
message: 'Authorized request to Webhook Sample Node.js.',
status: 200
}
console.log(response.message)
// Business logic here, example make API request to Zoom.

}
} else {
response = {
message: 'Unauthorized request to Webhook Sample Node.js.',
status: 401
}
console.log(response.message)

res.status(response.status)
res.json(response)
}
})

app.listen(port, function (){
console.log(`Example Zoom app listening at port ${port}!`)
})
Loading