Created
May 9, 2021 16:31
-
-
Save ayanchoudhary/41679e4e36953ebe3a53c2e65744bc52 to your computer and use it in GitHub Desktop.
callback function
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
| 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