I have been trying to convert this node.js script to a comparable version to use as a function in google sheets via google apps script. I have tried to do the conversion by piecing together various bits of code, but I just receive an error any time I try to use the code. I'm planning on using this to generate a signature needed to embed zoom into my website using the SDK at the time of the zoom meeting.
Here is the code below:
const crypto = require('crypto') // crypto comes with Node.js
function generateSignature(apiKey, apiSecret, meetingNumber, role) {
// Prevent time sync issue between client signature generation and Zoom
const timestamp = new Date().getTime() - 30000
const msg = Buffer.from(apiKey + meetingNumber + timestamp + role).toString('base64')
const hash = crypto.createHmac('sha256', apiSecret).update(msg).digest('base64')
const signature = Buffer.from(apiKey, meetingNumber, timestamp, role, hash).toString('base64')
return signature
}
// pass in your Zoom JWT API Key, Zoom JWT API Secret, Zoom Meeting Number, and 0 to join meeting or webinar or 1 to start meeting
console.log(generateSignature(process.env.API_KEY, process.env.API_SECRET, 123456789, 0))
I would really appreciate any insight! Thank you so much in advance!
UPDATE: This code works perfect for Node.js; however, I am trying to convert this to the same functionality within google Apps Script, which is a type of Javascript. One thing I noticed is that Google Apps Script does not support the "const crypto = require('crypto')" function. I'm unsure of how to convert this to receive the same output in Google Apps Script which will be applied to a Google Sheets document
Thank you again for any insight!
const signature = Buffer.from(apiKey, meetingNumber, timestamp, role, hash).toString('base64'), onlyapiKeyis used. In this case, I think that your script is same withconst generateSignature = (apiKey) => Buffer.from(apiKey).toString("base64");. So, I cannot understand whether your showing script works fine. And, I'm worried that you might have miscopied your script. When you run your showing script using your variables ofapiKey, apiSecret, meetingNumber, role, your goal can be achieved?cryptofunctionality, which is part of Node's standard library, not the JS language itself. So if Google's App Script has a cryptography library available, then you might be able to use that, but if it doesn't, you're probably out of luck. Having said that: why do you need this in google sheets? What are you trying to implement that makes you think that this is one of the steps that is required to facilitate that work? Because sheets run client-side, which means you'd be trivially leaking secrets that anyone on a page with that script can steal.