0

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!

TheMaster
  • 45,448
  • 6
  • 62
  • 85
ZP1306
  • 1
  • 1
  • You really want to change that title to be as focused on the actual problem as possible, because node.js is a programming language, google sheets is a web application, and the zoom SDK is code... so your title is an amazing head scratcher =) – Mike 'Pomax' Kamermans Jun 29 '22 at 23:52
  • I think that in your showing script, at `const signature = Buffer.from(apiKey, meetingNumber, timestamp, role, hash).toString('base64')`, only `apiKey` is used. In this case, I think that your script is same with `const 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 of `apiKey, apiSecret, meetingNumber, role`, your goal can be achieved? – Tanaike Jun 30 '22 at 01:38
  • In this case i'm trying to convert this bit of code to the javascript form that is supported by Google Apps Script – ZP1306 Jun 30 '22 at 15:00
  • The script you're showing relies on Node's `crypto` functionality, 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. – Mike 'Pomax' Kamermans Jun 30 '22 at 15:51
  • @Mike'Pomax'Kamermans Apps script runs on the server. – TheMaster Jun 30 '22 at 20:02

0 Answers0