-
Notifications
You must be signed in to change notification settings - Fork 50
/
index.js
72 lines (61 loc) · 2.27 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//include required modules
const jwt = require('jsonwebtoken');
const config = require('./config');
const rp = require('request-promise');
const express = require('express');
const app = express();
app.use(express.urlencoded({ extended: true }));
app.use(express.static('public'));
var email, userid, resp;
const port = 3000;
//Use the ApiKey and APISecret from config.js
const payload = {
iss: config.APIKey,
exp: ((new Date()).getTime() + 5000)
};
const token = jwt.sign(payload, config.APISecret);
//get the form
app.get('/', (req,res) => res.send(req.body));
//use userinfo from the form and make a post request to /userinfo
app.post('/userinfo', (req, res) => {
//store the email address of the user in the email variable
email = req.body.email;
//check if the email was stored in the console
console.log(email);
//Store the options for Zoom API which will be used to make an API call later.
var options = {
//You can use a different uri if you're making an API call to a different Zoom endpoint.
uri: "https://api.zoom.us/v2/users/"+email,
qs: {
status: 'active'
},
auth: {
'bearer': token
},
headers: {
'User-Agent': 'Zoom-api-Jwt-Request',
'content-type': 'application/json'
},
json: true //Parse the JSON string in the response
};
//Use request-promise module's .then() method to make request calls.
rp(options)
.then(function (response) {
//printing the response on the console
console.log('User has', response);
//console.log(typeof response);
resp = response
//Adding html to the page
var title1 ='<center><h3>Your token: </h3></center>'
var result1 = title1 + '<code><pre style="background-color:#aef8f9;">' + token + '</pre></code>';
var title ='<center><h3>User\'s information:</h3></center>'
//Prettify the JSON format using pre tag and JSON.stringify
var result = title + '<code><pre style="background-color:#aef8f9;">'+JSON.stringify(resp, null, 2)+ '</pre></code>'
res.send(result1 + '<br>' + result);
})
.catch(function (err) {
// API call failed...
console.log('API call failed, reason ', err);
});
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`));