Last active
November 17, 2017 00:26
-
-
Save joshuawoodward/a32dfcce59c14016f0f539a8fe6357a8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var request = require('request'); | |
const client_id = '<client_id>'; | |
const client_secret = '<client_secret>'; | |
const redirect_uri = 'http://localhost:8080/oauth'; | |
module.exports = function (req, res) { | |
//this will check if the code parameter is in the url, if not the most liekly case is that this is the user's inital visit to oauth and we need to redirect them (step 1) | |
//if there is a code, it most likely means they were redirected here from zoom oauth screen | |
if (req.query.code) { | |
let url = 'https://zoom.us/oauth/token?grant_type=authorization_code&code=' + req.query.code + '&redirect_uri=' + redirect_uri; | |
//STEP 3 | |
//we need to exchange the code for a oauth token | |
request.post(url, function (error, response, body) { | |
//the response should be a JSON payload | |
body = JSON.parse(body); | |
//and contain an access token | |
if (body.access_token) { | |
//STEP 4 | |
//we can now use the access token to make API calls | |
request.get('https://zoom.us/api/profile', function (error, response, body) { | |
//do something with the data | |
//this is most likely where you want to connect the zoom user to the calendly user, there will be a zoom user id | |
//add where you'll want to store the access token for future requests | |
}).auth(null, null, true, body.access_token); | |
} else { | |
//handle error, something went wrong | |
} | |
}).auth(client_id, client_secret); | |
return; | |
} | |
//STEP 2 | |
//no code provide, so redirect the user to get code | |
res.redirect('https://zoom.us/oauth/authorize?response_type=code&client_id=' + client_id + '&redirect_uri=' + redirect_uri); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment