Description
After the user authenticates my app, I then get a invalid authorization code error returned from the api endpoint.
Error
reason: ‘Invalid authorization code 2eVuv4dL4b_ZMs9PfYuSe6LhmQF6Fw45w’,
Which App Type (OAuth / Chatbot / JWT / Webhook)?
OAuth - Account level
Which Endpoint/s?
https://zoom.us/oauth/token?grant_type=authorization_code
Additional context
Here is my code currently:
app.get('/create', (req, res) => {
// Step 1:
// Check if the code parameter is in the url
// if an authorization code is available, the user has most likely been redirected from Zoom OAuth
// if not, the user needs to be redirected to Zoom OAuth to authorize
if (req.query.code) {
// Step 3:
// Request an access token using the auth code
console.log('Code returned', req.query.code);
let url = 'https://zoom.us/oauth/token?grant_type=authorization_code&code=' + req.query.code + '&redirect_uri='+process.env.redirectURL+'/create';
rp.post(url, (error, response, body) => {
// Parse response to JSON
body = JSON.parse(body);
console.log(body);
// Logs your access and refresh tokens in the browser
console.log(`access_token: ${body.access_token}`);
console.log(`refresh_token: ${body.refresh_token}`);
if (body.access_token) {
// Step 4:
// We can now use the access token to authenticate API calls
// Send a request to get your user information using the /me context
// The `/me` context restricts an API call to the user the token belongs to
// This helps make calls to user-specific endpoints instead of storing the userID
const options = {
uri: "https://api.zoom.us/v2/users/me/meetings",
auth: {
'bearer': body.access_token
},
method: 'POST',
headers: {
'User-Agent': 'Zoom-api-Jwt-Request',
'content-type': 'application/json'
},
json: true, //Parse the JSON string in the response
body:{
"topic": "Test Meeting",
"type": 1,
"agenda": "Talking about firebase.",
"join_before_host": true,
"settings": {
"host_video": false,
"participant_video": true,
"mute_upon_entry": true,
"watermark": false,
"audio": "voip",
"auto_recording": "cloud",
"use_pmi":true
}
}
}
rp(options, (error, response, body) => {
if (error) {
console.log('API Response Error: ', error)
} else {
body = JSON.parse(body);
// Display response in console
console.log('API call ', body);
// Display response in browser
var JSONResponse = '<pre><code>' + JSON.stringify(body, null, 2) + '</code></pre>'
res.send(JSONResponse);
}
}).auth(null, null, true, body.access_token);
} else {
// Handle errors, something's gone wrong!
}
}).auth(process.env.clientID, process.env.clientSecret);
return;
}
// Step 2:
// If no authorization code is available, redirect to Zoom OAuth to authorize
res.redirect('https://zoom.us/oauth/authorize?response_type=code&client_id=' +process.env.clientID + '&redirect_uri=https://jive-zoom.web.app/create')
});