├── README.md ├── config.js ├── index.js ├── package.json └── public ├── index.html └── styles.css /README.md: -------------------------------------------------------------------------------- 1 | # Make Zoom API call using JWT 2 | 3 | > With this app, you can learn how to generate JWT and use the JWT to authenticate and make a Zoom API call. Follow the steps below to install the app and run it on your computer. 4 | 5 | ## Getting Started 6 | 7 | ### Install 8 | 9 | Clone the repo using git clone. 10 | `git clone https://github.com/zoom/zoom-api-jwt.git` 11 | 12 | > Install the dependent node modules by typing `npm-install` in your terminal. 13 | 14 | The app requires the following modules: 15 | 16 | >jsonwebtoken : Provides a way to generate JWT with jwt.sign() method. 17 | >request-promise: Provides a way to Request call objects with .then() method. 18 | >express: Web application framework for Node.js. 19 | 20 | ### Quick Start 21 | 22 | To generate JWT, you have to provide your API Key and API Secret credentials. You can locate these credentials in your app’s configuration by going to `Zoom Marketplace > Manage > > App Credentials`. If you haven’t already registered your app in the marketplace, you will have to create an app here to get your credentials. For the purpose of this sample app, you only need your credentials and you do not have to fill out any additional information while registering the app. 23 | 24 | > In the config.js file, input your client API Key & Secret credentials. 25 | 26 | ``` 27 | const config = { 28 | production:{ 29 | APIKey: 'Your environment API Key', 30 | APISecret: 'Your environment API Secret' 31 | } 32 | }; 33 | ``` 34 | 35 | > Start the node app. 36 | Type `node index.js` in your terminal from within the project directory. 37 | 38 | > Enter your email and view the API's response. 39 | When you run the app, you will see a form that asks for an email address. Provide your Zoom email address and you will see your JWT and other information related to your account. 40 | 41 | The following code snippet generates the JWT using your Client Credentials: 42 | 43 | ``` 44 | const payload = { 45 | iss: config.APIKey, 46 | exp: (new Date()).getTime() + 5000 47 | }; 48 | 49 | const token = jwt.sign(payload, config.APISecret); 50 | ``` 51 | 52 | After you submit an email address, it will post the entered information and the email will be used to make a **Retrieve User** Zoom API call and you will be redirected to localhost:3000/userinfo page that displays the API response - information related to the user. This is achieved through an HTTP POST method. You can make API calls to other ZOOM endpoints by replacing the uri shown in the snippet below with another uri of your choice. You can find more about ZOOM APIs here. 53 | 54 | ``` 55 | const options = { 56 | uri: `https://api.zoom.us/v2/users/${email}`, 57 | qs: { 58 | 'status': 'active' 59 | }, 60 | auth: { 61 | 'bearer': token 62 | }, 63 | headers: { 64 | 'User-Agent': 'Zoom-api-Jwt-Request', 65 | 'content-type': 'application/json' 66 | }, 67 | json: true // Parse the JSON string in the response 68 | }; 69 | ``` 70 | 71 | ### For more Information about Zooms API and JWT 72 | 73 | Documentation for JWT is available [here](https://marketplace.zoom.us/docs/guides/authorization/jwt). You can learn more about Zoom API [here](https://marketplace.zoom.us/docs/api-reference/introduction). 74 | 75 | ## Need help? 76 | 77 | If you're looking for help, try [Developer Support](https://devsupport.zoom.us) or our [Developer Forum](https://devforum.zoom.us). Priority support is also available with [Premier Developer Support](https://zoom.us/docs/en-us/developer-support-plans.html) plans. 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /config.js: -------------------------------------------------------------------------------- 1 | const env = 'production' 2 | 3 | //insert your API Key & Secret for each environment, keep this file local and never push it to a public repo for security purposes. 4 | const config = { 5 | production:{ 6 | APIKey : '', 7 | APISecret : '' 8 | } 9 | }; 10 | 11 | module.exports = config[env] 12 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | //include required modules 2 | const jwt = require('jsonwebtoken'); 3 | const config = require('./config'); 4 | const rp = require('request-promise'); 5 | 6 | const express = require('express'); 7 | const app = express(); 8 | app.use(express.urlencoded({ extended: true })); 9 | app.use(express.static('public')); 10 | var email, userid, resp; 11 | const port = 3000; 12 | 13 | //Use the ApiKey and APISecret from config.js 14 | const payload = { 15 | iss: config.APIKey, 16 | exp: ((new Date()).getTime() + 5000) 17 | }; 18 | const token = jwt.sign(payload, config.APISecret); 19 | 20 | 21 | //get the form 22 | app.get('/', (req,res) => res.send(req.body)); 23 | 24 | //use userinfo from the form and make a post request to /userinfo 25 | app.post('/userinfo', (req, res) => { 26 | //store the email address of the user in the email variable 27 | email = req.body.email; 28 | //check if the email was stored in the console 29 | console.log(email); 30 | //Store the options for Zoom API which will be used to make an API call later. 31 | var options = { 32 | //You can use a different uri if you're making an API call to a different Zoom endpoint. 33 | uri: "https://api.zoom.us/v2/users/"+email, 34 | qs: { 35 | status: 'active' 36 | }, 37 | auth: { 38 | 'bearer': token 39 | }, 40 | headers: { 41 | 'User-Agent': 'Zoom-api-Jwt-Request', 42 | 'content-type': 'application/json' 43 | }, 44 | json: true //Parse the JSON string in the response 45 | }; 46 | 47 | //Use request-promise module's .then() method to make request calls. 48 | rp(options) 49 | .then(function (response) { 50 | //printing the response on the console 51 | console.log('User has', response); 52 | //console.log(typeof response); 53 | resp = response 54 | //Adding html to the page 55 | var title1 ='

Your token:

' 56 | var result1 = title1 + '
' + token + '
'; 57 | var title ='

User\'s information:

' 58 | //Prettify the JSON format using pre tag and JSON.stringify 59 | var result = title + '
'+JSON.stringify(resp, null, 2)+ '
' 60 | res.send(result1 + '
' + result); 61 | 62 | }) 63 | .catch(function (err) { 64 | // API call failed... 65 | console.log('API call failed, reason ', err); 66 | }); 67 | 68 | 69 | }); 70 | 71 | 72 | app.listen(port, () => console.log(`Example app listening on port ${port}!`)); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "zoom-api-jwt", 3 | "version": "1.0.0", 4 | "description": "Zoom API JWT Sample app", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Michael Purnell", 10 | "license": "ISC", 11 | "dependencies": { 12 | "express": "^4.16.3", 13 | "jsonwebtoken": "^8.3.0", 14 | "request": "^2.87.0", 15 | "request-promise": "^4.2.2" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Home Page 5 | 6 | 7 | 8 |
9 |

Enter a user's email address below. Once you submit it, we will use the jwt generated for your account to authenticate the request and provide you with the information related to the user by making this API call.

10 |
11 |
12 |
13 |
14 |
15 | 16 | 17 |
18 |
19 |
20 | 21 |
22 |
23 |
24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /public/styles.css: -------------------------------------------------------------------------------- 1 | * { 2 | box-sizing: border-box; 3 | 4 | } 5 | 6 | input[type=text] { 7 | width: 100%; 8 | padding: 12px; 9 | border: 1px solid #ccc; 10 | border-radius: 4px; 11 | resize: vertical; 12 | } 13 | 14 | label { 15 | padding: 12px 12px 12px 0; 16 | display: inline-block; 17 | } 18 | 19 | input[type=submit] { 20 | background-color: #42a7f4; 21 | color: white; 22 | padding: 12px; 23 | border: none; 24 | border-radius: 4px; 25 | cursor: pointer; 26 | } 27 | 28 | input[type=submit]:hover { 29 | background-color: #c741f4; 30 | } 31 | 32 | .container { 33 | border-radius: 5px; 34 | background-color: #f2f2f2; 35 | padding: 20px; 36 | } 37 | 38 | .col-25 { 39 | float: left; 40 | width: 25%; 41 | margin-top: 6px; 42 | } 43 | 44 | 45 | 46 | /* Add floats after the columns */ 47 | .row:after { 48 | content: ""; 49 | display: table; 50 | clear: both; 51 | } 52 | 53 | /* Responsive layout*/ 54 | @media screen and (max-width: 600px) { 55 | .col-25, input[type=submit] { 56 | width: 100%; 57 | margin-top: 0; 58 | } 59 | } --------------------------------------------------------------------------------