Skip to content

Instantly share code, notes, and snippets.

@ayanchoudhary
Created May 9, 2021 16:31
Show Gist options
  • Select an option

  • Save ayanchoudhary/41679e4e36953ebe3a53c2e65744bc52 to your computer and use it in GitHub Desktop.

Select an option

Save ayanchoudhary/41679e4e36953ebe3a53c2e65744bc52 to your computer and use it in GitHub Desktop.
callback function
app.get('/callback', function (req, res) {
/* Retrieve authorization code from request */
let code = req.query.code;
let requestId = req.query.state;
/* Set options with required paramters */
let requestOptions = {
uri: `https://api.dropboxapi.com/oauth2/token?grant_type=authorization_code&code=${code}&client_id=${dropboxApiKey}&client_secret=${dropboxApiSecret}&redirect_uri=${publicUrl}/callback`,
method: 'POST',
json: true
}
/* Send a POST request using the request library */
request(requestOptions)
.then(function (response) {
/* Store the token in req.session.token */
req.session.token = response.access_token;
/* Simulating writing to a database */
requestIds[requestId]["accessToken"] = response.access_token;
res.send('Authentication successful. You can close this tab');
})
.catch(function (error) {
res.json({ 'response': 'Log in failed!' });
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment